Add basic memory usage debugging
This commit is contained in:
28
src/c/main.c
28
src/c/main.c
@@ -1,6 +1,9 @@
|
|||||||
#include "palette_manip.h"
|
#include "palette_manip.h"
|
||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
|
|
||||||
|
// DEBUG memory usage layer
|
||||||
|
static TextLayer *s_memory_layer;
|
||||||
|
|
||||||
// declare general statics
|
// declare general statics
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static GFont s_custom_font;
|
static GFont s_custom_font;
|
||||||
@@ -81,6 +84,11 @@ static void update_minute_1() {
|
|||||||
|
|
||||||
text_layer_set_text(s_time_layer, s_time_buffer);
|
text_layer_set_text(s_time_layer, s_time_buffer);
|
||||||
text_layer_set_text(s_date_layer, s_date_buffer);
|
text_layer_set_text(s_date_layer, s_date_buffer);
|
||||||
|
|
||||||
|
// DEBUG memory usage layer
|
||||||
|
static char s_memory_buffer[32];
|
||||||
|
snprintf(s_memory_buffer, sizeof(s_memory_buffer), "%d/%d", (int)heap_bytes_used(), (int)heap_bytes_free() + (int)heap_bytes_used());
|
||||||
|
text_layer_set_text(s_memory_layer, s_memory_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_minute_30_out_handler(Animation *animation, bool finished, void *context) {
|
static void update_minute_30_out_handler(Animation *animation, bool finished, void *context) {
|
||||||
@@ -221,6 +229,13 @@ static void main_window_load(Window *window) {
|
|||||||
layer_set_update_proc(s_time_bar_layer, time_bar_update_proc);
|
layer_set_update_proc(s_time_bar_layer, time_bar_update_proc);
|
||||||
text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
|
text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
|
||||||
|
|
||||||
|
// DEBUG memory usage layer
|
||||||
|
s_memory_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(220, 190), PBL_IF_ROUND_ELSE(260, 200), 14));
|
||||||
|
text_layer_set_background_color(s_memory_layer, GColorClear);
|
||||||
|
text_layer_set_font(s_memory_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
|
||||||
|
text_layer_set_text_color(s_memory_layer, GColorWhite);
|
||||||
|
PBL_IF_ROUND_ELSE(text_layer_set_text_alignment(s_memory_layer, GTextAlignmentCenter), text_layer_set_text_alignment(s_memory_layer, GTextAlignmentLeft));
|
||||||
|
|
||||||
// add layers as children to window
|
// add layers as children to window
|
||||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_head_layer));
|
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_head_layer));
|
||||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_butt_layer));
|
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_butt_layer));
|
||||||
@@ -228,16 +243,22 @@ static void main_window_load(Window *window) {
|
|||||||
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
|
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
|
layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
|
||||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_bt_layer));
|
layer_add_child(window_layer, bitmap_layer_get_layer(s_bt_layer));
|
||||||
|
|
||||||
|
// DEBUG memory usage layer
|
||||||
|
layer_add_child(window_layer, text_layer_get_layer(s_memory_layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
// free memory on Window close;
|
// free memory on Window close
|
||||||
// this means matching all "_create"'s from main_window_load with "_destroy"
|
|
||||||
static void main_window_unload(Window *window) {
|
static void main_window_unload(Window *window) {
|
||||||
bitmap_layer_destroy(s_guy_head_layer);
|
bitmap_layer_destroy(s_guy_head_layer);
|
||||||
bitmap_layer_destroy(s_guy_butt_layer);
|
bitmap_layer_destroy(s_guy_butt_layer);
|
||||||
text_layer_destroy(s_time_layer);
|
text_layer_destroy(s_time_layer);
|
||||||
text_layer_destroy(s_date_layer);
|
text_layer_destroy(s_date_layer);
|
||||||
|
layer_destroy(s_time_bar_layer);
|
||||||
fonts_unload_custom_font(s_custom_font);
|
fonts_unload_custom_font(s_custom_font);
|
||||||
|
|
||||||
|
// DEBUG memory usage layer
|
||||||
|
text_layer_destroy(s_memory_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void up_single_click_handler(ClickRecognizerRef recognizer, void *context) {
|
static void up_single_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||||
@@ -300,8 +321,7 @@ static void init() {
|
|||||||
window_set_click_config_provider(s_main_window, (ClickConfigProvider)click_config_provider);
|
window_set_click_config_provider(s_main_window, (ClickConfigProvider)click_config_provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free memory on app exit;
|
// free memory on app exit
|
||||||
// this means matching all "_create"'s from init() with "_destroy"
|
|
||||||
static void deinit() {
|
static void deinit() {
|
||||||
gbitmap_destroy(s_head_current);
|
gbitmap_destroy(s_head_current);
|
||||||
gbitmap_destroy(s_butt_current);
|
gbitmap_destroy(s_butt_current);
|
||||||
|
|||||||
Reference in New Issue
Block a user