Skip to content

Instantly share code, notes, and snippets.

@tkafka
Last active October 8, 2016 16:34
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkafka/7573581e56d8eca51329 to your computer and use it in GitHub Desktop.
Save tkafka/7573581e56d8eca51329 to your computer and use it in GitHub Desktop.
Optimizing app size (for aplite): script to show code space size for every function. I noticed that you can read size of every function from build/pebble-app.map. So, here's a script to do it :)).
#!/usr/bin/env bash
cat ./build/pebble-app.map |
# pick important part of file
sed -n -e "/^ \*(\.text\.\*)/,/^ \*(\.rodata)/p" |
# remove first and last line
sed -e "1d" -e "\$d" |
# ensure every function is on single line:
# remove all newlines
sed -e :a -e '$!N; s/\n/ /; ta' |
# replace .text. with \n.text. (add newlines)
sed -e $'s/\.text\./\\\n.text./g' |
# cut into columns:
# replace whitespaces with ;
sed -e 's/ */;/g' |
# extract columns 1-3
cut -d ';' -f1 -f2 -f3 |
# remove .text. from function name
sed -e 's/^\.text\.//g' |
# columns: 1 = function name, 2 = fn start offset, 3 = fn code length
# print <length> <function>
awk -F ';' '{printf "%d %s\n", $3+0, $1 }' |
# general numeric (-g) sort by 1st column
sort -r -t ' ' -k 1,1 -g |
cat
440 time_layer_update_callback
388 preferences_load
328 weather_load_cache
312 preferences_save
268 in_received_handler
252 weather_save_cache
228 graphics_draw_text_outline
194 preferences_set
180 change_preferences
156 handle_tick
144 window_unload
122 weather_set
104 weather_create
84 url_decode
68 weather_request_on_start
68 out_failed_handler
60 deinit
56 on_weather_changed
56 get_time_frame
50 weather_request_if_needs_update
50 weather_groom_cache
48 handle_bluetooth
48 get_weather_frame
46 appmessage_dictionary_has_weather
44 weather_destroy
40 set_weather_visible_animation_stopped_handler
36 in_dropped_handler
36 get_status_frame
36 getSystemTimeMs
32 update_weather_info
32 out_sent_handler
30 force_tick
28 has_internet_connection
24 weather_is_valid
24 hex_digit_value
18 startup.main
18 layer_destroy_and_null
18 bitmap_layer_destroy_and_null
18 bitmap_destroy_and_null
16 appmessage_dictionary_js_app_ready
16 appmessage_dictionary_has_preferences
16 appmessage_dictionary_config_opened
14 to_lower
12 window_stack_push
12 window_set_window_handlers
12 window_set_background_color
12 window_get_root_layer
12 window_destroy
12 window_create
12 time_ms
12 time
12 tick_timer_service_unsubscribe
12 tick_timer_service_subscribe
12 strncpy
12 strlen
12 strftime
12 strcpy
12 srand
12 snprintf
12 resource_get_handle
12 property_animation_get_animation
12 property_animation_create_layer_frame
12 persist_write_string
12 persist_write_int
12 persist_write_data
12 persist_read_string
12 persist_read_int
12 persist_read_data
12 persist_exists
12 persist_delete
12 memset
12 memcpy
12 malloc
12 localtime
12 layer_set_update_proc
12 layer_set_hidden
12 layer_set_frame
12 layer_mark_dirty
12 layer_get_frame
12 layer_get_bounds
12 layer_destroy
12 layer_create
12 layer_add_child
12 graphics_text_layout_get_content_size
12 graphics_fill_rect
12 graphics_fill_circle
12 graphics_draw_text
12 graphics_draw_pixel
12 graphics_draw_line
12 graphics_context_set_text_color
12 graphics_context_set_stroke_width
12 graphics_context_set_stroke_color
12 graphics_context_set_fill_color
12 gbitmap_destroy
12 free
12 fonts_unload_custom_font
12 fonts_load_custom_font
12 fonts_get_system_font
12 difftime
12 dict_write_tuplet
12 dict_find
12 connection_service_unsubscribe
12 connection_service_subscribe
12 connection_service_peek_pebble_app_connection
12 clock_copy_time_string
12 bluetooth_connection_service_peek
12 bitmap_layer_destroy
12 battery_state_service_unsubscribe
12 battery_state_service_subscribe
12 battery_state_service_peek
12 app_message_register_outbox_sent
12 app_message_register_outbox_failed
12 app_message_register_inbox_received
12 app_message_register_inbox_dropped
12 app_message_outbox_send
12 app_message_outbox_begin
12 app_message_open
12 app_log
12 app_event_loop
12 animation_set_handlers
12 animation_set_duration
12 animation_set_delay
12 animation_set_curve
12 animation_schedule
12 animation_destroy
10 weather_needs_update_hystersis
6 weather_out_sent_handler
6 weather_out_failed_handler
6 weather_needs_update_on_start
6 weather_needs_update
6 weather_is_outdated
6 handle_battery
6 getTime
4 animation_stopped_handler
@starrodkirby86
Copy link

Hi, awesome work. It's really helped me take a look at functions that seem to be occupying the most space and easily reading that extensive .map file.

Oddly enough, I got an error from line 20, saying that only one type of list may be specified. Commenting out the line though worked. The cut command claims that it can only do one cut operation at some point, so maybe that's related? I don't have any experience in bash scripting, so I found it out already odd that it didn't work for me when trying to just "plug and play".

Anyway, thank you for sharing this!

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