Created
September 17, 2015 06:11
-
-
Save yourtion/1962151f11c36242fe96 to your computer and use it in GitHub Desktop.
ios_report_memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void report_memory(void) { | |
static unsigned last_resident_size=0; | |
static unsigned greatest = 0; | |
static unsigned last_greatest = 0; | |
struct task_basic_info info; | |
mach_msg_type_number_t size = sizeof(info); | |
kern_return_t kerr = task_info(mach_task_self(), | |
TASK_BASIC_INFO, | |
(task_info_t)&info, | |
&size); | |
if( kerr == KERN_SUCCESS ) { | |
int diff = (int)info.resident_size - (int)last_resident_size; | |
unsigned latest = info.resident_size; | |
if( latest > greatest ) greatest = latest; // track greatest mem usage | |
int greatest_diff = greatest - last_greatest; | |
int latest_greatest_diff = latest - greatest; | |
NSLog(@"Mem: %10u (%10d) : %10d : greatest: %10u (%d)", info.resident_size, diff, | |
latest_greatest_diff, | |
greatest, greatest_diff ); | |
} else { | |
NSLog(@"Error with task_info(): %s", mach_error_string(kerr)); | |
} | |
last_resident_size = info.resident_size; | |
last_greatest = greatest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment