-
Notifications
You must be signed in to change notification settings - Fork 3k
Add pretty bars for compile output #5929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,9 +9,11 @@ | |||||||||||||||||||||||
| import re | ||||||||||||||||||||||||
| import csv | ||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||
| import math | ||||||||||||||||||||||||
| from argparse import ArgumentParser | ||||||||||||||||||||||||
| from copy import deepcopy | ||||||||||||||||||||||||
| from prettytable import PrettyTable | ||||||||||||||||||||||||
| from tools.arm_pack_manager import Cache | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from utils import argparse_filestring_type, \ | ||||||||||||||||||||||||
| argparse_lowercase_hyphen_type, argparse_uppercase_type | ||||||||||||||||||||||||
|
|
@@ -506,7 +508,7 @@ def reduce_depth(self, depth): | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export_formats = ["json", "csv-ci", "table"] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def generate_output(self, export_format, depth, file_output=None): | ||||||||||||||||||||||||
| def generate_output(self, export_format, depth, file_output=None, *args): | ||||||||||||||||||||||||
| """ Generates summary of memory map data | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Positional arguments: | ||||||||||||||||||||||||
|
|
@@ -531,8 +533,9 @@ def generate_output(self, export_format, depth, file_output=None): | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| to_call = {'json': self.generate_json, | ||||||||||||||||||||||||
| 'csv-ci': self.generate_csv, | ||||||||||||||||||||||||
| 'table': self.generate_table}[export_format] | ||||||||||||||||||||||||
| output = to_call(file_desc) | ||||||||||||||||||||||||
| 'table': self.generate_table, | ||||||||||||||||||||||||
| 'bars': self.generate_bars}[export_format] | ||||||||||||||||||||||||
| output = to_call(file_desc, *args) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if file_desc is not stdout: | ||||||||||||||||||||||||
| file_desc.close() | ||||||||||||||||||||||||
|
|
@@ -616,6 +619,71 @@ def generate_table(self, file_desc): | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return output | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def generate_bars(self, file_desc, device_name=None): | ||||||||||||||||||||||||
| """ Generates nice looking bars that represent the memory consumption | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Returns: string containing nice looking bars | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # TODO add tty detection, and width detection probably | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this a TODO you wanted to address before merging or is it fine as is?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either or. You can see the current width detection below, which will only work on Linux (but doesn't hurt other OSs): Lines 628 to 638 in a4bfd01
I'm not planning on adding support for other OSs at this time, though I don't think that should stop this PR, they're just stuck at a 72 character width. I did search briefly, but unfortunately finding cross-platform screen width is a nightmare in python 2.7.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. |
||||||||||||||||||||||||
| WIDTH = 72 | ||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||
| # NOTE this only works on linux | ||||||||||||||||||||||||
| import sys, fcntl, termios, struct | ||||||||||||||||||||||||
| height, width, _, _ = struct.unpack('HHHH', | ||||||||||||||||||||||||
| fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, | ||||||||||||||||||||||||
| struct.pack('HHHH', 0, 0, 0, 0))) | ||||||||||||||||||||||||
| WIDTH = min(width, WIDTH) | ||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| text = self.subtotal['.text'] | ||||||||||||||||||||||||
| data = self.subtotal['.data'] | ||||||||||||||||||||||||
| bss = self.subtotal['.bss'] | ||||||||||||||||||||||||
| rom_used = self.mem_summary['total_flash'] | ||||||||||||||||||||||||
| ram_used = self.mem_summary['static_ram'] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # No device_name = no cmsis-pack = we don't know the memory layout | ||||||||||||||||||||||||
| if device_name is not None: | ||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||
| cache = Cache(False, False) | ||||||||||||||||||||||||
| cmsis_part = cache.index[device_name] | ||||||||||||||||||||||||
| rom_avail = int(cmsis_part['memory']['IROM1']['size'], 0) | ||||||||||||||||||||||||
| ram_avail = int(cmsis_part['memory']['IRAM1']['size'], 0) | ||||||||||||||||||||||||
| except KeyError: | ||||||||||||||||||||||||
| # If we don't have the expected regions, fall back to no device_name | ||||||||||||||||||||||||
| device_name = None | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| PREFIXES = ['', 'K', 'M', 'G', 'T', 'P', 'E'] | ||||||||||||||||||||||||
| def unit(n, u='B', p=3): | ||||||||||||||||||||||||
| if n == 0: | ||||||||||||||||||||||||
| return '0' + u | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| scale = math.floor(math.log(n, 1024)) | ||||||||||||||||||||||||
| return '{1:.{0}g}{2}{3}'.format(p, n/(1024**scale), PREFIXES[int(scale)], u) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| usage = "Text {} Data {} BSS {}".format(unit(text), unit(data), unit(bss)) | ||||||||||||||||||||||||
| avail = "ROM {} RAM {}".format(unit(rom_used), unit(ram_used)) | ||||||||||||||||||||||||
| output = ["{0} {1:>{2}}".format(usage, avail, | ||||||||||||||||||||||||
| abs(WIDTH-len(usage)-1) if device_name is not None else 0)] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if device_name is not None: | ||||||||||||||||||||||||
| for region, avail, uses in [ | ||||||||||||||||||||||||
| ('ROM', rom_avail, [('|', text), ('|', data)]), | ||||||||||||||||||||||||
| ('RAM', ram_avail, [('|', bss), ('|', data)])]: | ||||||||||||||||||||||||
| barwidth = WIDTH-17 - len(region) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| used = sum(use for c, use in uses) | ||||||||||||||||||||||||
| bars = [(c, (barwidth*use) // avail) for c, use in uses] | ||||||||||||||||||||||||
| bars.append((' ', barwidth - sum(width for c, width in bars))) | ||||||||||||||||||||||||
| bars = ''.join(c*width for c, width in bars) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| output.append("{0} [{2:<{1}}] {3:>13}".format( | ||||||||||||||||||||||||
| region, barwidth, bars, | ||||||||||||||||||||||||
| "{}/{}".format(unit(used), unit(avail)))) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return '\n'.join(output) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| toolchains = ["ARM", "ARM_STD", "ARM_MICRO", "GCC_ARM", "GCC_CR", "IAR"] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def compute_report(self): | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you hove these lines into the else statement below? that way we only generate what we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memap_table is also used by the build report below, and the generate_output has side-effects I'm not sure about. You can see it was originally outside of the
if not silentstatement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point.
It does a
compute_reportfollowed by areduce_depth, which will be run by the followinggenerate_outputcalls anyway.