Skip to content
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

Add pretty bars for compile output #5929

Merged
merged 1 commit into from
Jan 29, 2018
Merged

Add pretty bars for compile output #5929

merged 1 commit into from
Jan 29, 2018

Conversation

geky
Copy link
Contributor

@geky geky commented Jan 25, 2018

Looks like this:

$ mbed compile -m ARCH_PRO -t GCC_ARM
Building project mbed-os-prettyoutput (ARCH_PRO, GCC_ARM)
Scan: .
Scan: env
Scan: mbed
Scan: FEATURE_LWIP
Text 70.5KB Data 2.72KB BSS 7.43KB                 ROM 73.2KB RAM 10.1KB
ROM [|||||||                                             ]  73.2KB/512KB
RAM [||||||||||||||||                                    ]   10.1KB/32KB
Image: BUILD/ARCH_PRO/GCC_ARM/mbed-os-prettyoutput.bin

This is an alternative to the pretty table output that provides useful information about memory consumption without using as much screen real-estate as the pretty table output. You may also note this matches what is displayed on the website, which is an added plus.

cc @theotherjimmy, @0xc0170

Returns: string containing nice looking bars
"""

# TODO add tty detection, and width detection probably
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@geky geky Jan 25, 2018

Choose a reason for hiding this comment

The 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):

mbed-os/tools/memap.py

Lines 628 to 638 in a4bfd01

# TODO add tty detection, and width detection probably
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:
pass

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

@kegilbert
Copy link
Contributor

I like it!

Sorry if I misundertood, but is there a compile flag to allow a user to specify which format they'd like (table versus graph)? Looks like the table print was removed completely.

@geky
Copy link
Contributor Author

geky commented Jan 25, 2018

Updated 👍

I repurposed --stats-depth to revert back to pretty table printing. So no --stats-depth = pretty bars.

@drewcassidy
Copy link
Contributor

this might be out of scope but there are unicode characters for doing progress bars at different subdivisions of one character, U+2588 █ through U+258F ▏

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 25, 2018

Looks neat 👍

This is using cmsis packs - what happens if device is not yet in the index ? From the code looks like it would fail? As I recall they are used for bootloader or exporters, with this change would be also for compilation. In case of exporter, if device is not yet in the packs, it fails for uvision to export. What is the case for compilation with this patch?

@geky
Copy link
Contributor Author

geky commented Jan 25, 2018

@drewcassidy, Oh that's a good idea. Although it would look bad on non-unicode terminals. Do you know if there's a way to detect unicode support from a terminal? Do you think we can rely on $LANG?

@0xc0170, good point, I'll wrap all of this in a try catch based on cmsis-pack availability.

@drewcassidy
Copy link
Contributor

Do you think we can rely on $LANG?

$LANG appears to work, at least in iterm and terminal on macOS. You could only enable it if $LANG explicitly mentions UTF-8, and/or have a global flag to disable it like some tools have for color support. I was thinking of contributing to prettytable to add unicode block drawing support, so the flag could be used for configuring that as well

@geky
Copy link
Contributor Author

geky commented Jan 25, 2018

@0xc0170, updated, @theotherjimmy suggested I can rely on the presence of device_name in the target object to indicate if cmsis-packs are available. CI can now verify that claim :)

Here's the output without a cmsis-pack, though I'm open to suggestions if we want to see something different:

$ mbed compile -m ARM_BEETLE_SOC -t GCC_ARM
Building project mbed-os-prettyoutput (ARM_BEETLE_SOC, GCC_ARM)
Scan: .                                                        
Scan: env                                                      
Scan: mbed                                                     
Scan: FEATURE_BLE                                              
Text 99KB Data 2.84KB BSS 13KB ROM 102KB RAM 15.8KB            
Image: BUILD/ARM_BEETLE_SOC/GCC_ARM/mbed-os-prettyoutput.bin   

@geky
Copy link
Contributor Author

geky commented Jan 25, 2018

@drewcassidy, I think the unicode printing is a neat idea, but I don't think I'm going to be able to implement it at the moment. Feel free to add it in or include it when you add unicode support to the pretty tables.

@theotherjimmy
Copy link
Contributor

@geky Good pick of platform! that one probably won't ever have a CMSIS Pack. That output looks great! I'll review now.

@geky
Copy link
Contributor Author

geky commented Jan 25, 2018

@theotherjimmy, I just chose the first platform that CI failed on. Speaking of CI failures, apparently the NUCLEO_F767ZI doesn't have any ram? Updated with another catch on cmsis-pack parsing errors.

memap_table = memap_instance.generate_output('table', stats_depth)

real_stats_depth = stats_depth if stats_depth is None else 2
memap_table = memap_instance.generate_output('table', real_stats_depth)
Copy link
Contributor

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.

Copy link
Contributor Author

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 silent statement.

Copy link
Contributor

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

That's a good point.

generate_output has side-effects I'm not sure about

It does a compute_report followed by a reduce_depth, which will be run by the following generate_output calls anyway.

tools/memap.py Outdated
struct.pack('HHHH', 0, 0, 0, 0)))
WIDTH = min(width, WIDTH)
except:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you assign width to 72 here instead? and make that except not catch C-c and similar with

except Exception:
    WIDTH = 72

Copy link
Contributor Author

@geky geky Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIDTH is also used on line 636 (right above). Will update the second part of your sentence.

tools/memap.py Outdated

text = sum(module['size']['.text']
for module in self.mem_report
if 'size' in module)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be:

text = self.subtotal['.text']

tools/memap.py Outdated
if 'size' in module)
data = sum(module['size']['.data']
for module in self.mem_report
if 'size' in module)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be:

data = self.subtotal['.data']

tools/memap.py Outdated
if 'size' in module)
bss = sum(module['size']['.bss']
for module in self.mem_report
if 'size' in module)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be:

bss = self.subtotal['.bss']

tools/memap.py Outdated
bss = sum(module['size']['.bss']
for module in self.mem_report
if 'size' in module)
rom_used = text + data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be:

rom_used = self.mem_summary['total_flash']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just add them together? The math below would have problems if they differed

tools/memap.py Outdated
for module in self.mem_report
if 'size' in module)
rom_used = text + data
ram_used = data + bss
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be:

ram_used = self.mem_summary['static_ram']

@theotherjimmy
Copy link
Contributor

@geky Who knew? F767ZI has no RAM, huh.

Looks like this:

    Building project mbed-os-prettyoutput (ARCH_PRO, GCC_ARM)
    Scan: .
    Scan: env
    Scan: mbed
    Scan: FEATURE_LWIP
    Text 70.5KB Data 2.72KB BSS 7.43KB                 ROM 73.2KB RAM 10.1KB
    ROM [|||||||                                             ]  73.2KB/512KB
    RAM [||||||||||||||||                                    ]   10.1KB/32KB
    Image: BUILD/ARCH_PRO/GCC_ARM/mbed-os-prettyoutput.bin

If you build a target without a cmsis-pack it looks like this:

    Building project mbed-os-prettyoutput (ARM_BEETLE_SOC, GCC_ARM)
    Scan: .
    Scan: env
    Scan: mbed
    Scan: FEATURE_BLE
    Text 99KB Data 2.84KB BSS 13KB ROM 102KB RAM 15.8KB
    Image: BUILD/ARM_BEETLE_SOC/GCC_ARM/mbed-os-prettyoutput.bin

And the old behaviour of displaying the memap table can be brought back
by passing the --stats-depth parameter
@cmonr
Copy link
Contributor

cmonr commented Jan 26, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 26, 2018

Build : SUCCESS

Build number : 979
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5929/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@cmonr
Copy link
Contributor

cmonr commented Jan 26, 2018

uVisor tests are experiencing an anomaly. @0xc0170 has ping'd the team to determine how to resolve.

@mbed-ci
Copy link

mbed-ci commented Jan 27, 2018

@mbed-ci
Copy link

mbed-ci commented Jan 27, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 29, 2018

/morph uvisor-test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Jan 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants