Skip to content

Instantly share code, notes, and snippets.

@pykello
Created June 11, 2014 12:50
Show Gist options
  • Save pykello/49e1c8341376b913e3b6 to your computer and use it in GitHub Desktop.
Save pykello/49e1c8341376b913e3b6 to your computer and use it in GitHub Desktop.
static uint64 get_memory_usage() {
uint64 result = 0;
int i = 0;
bool seenSpace = false;
char statm[1024];
FILE *statmFile = fopen("/proc/self/statm", "r");
fread(statm, 1, 1024, statmFile);
fclose(statmFile);
for (i = 0; i < 1024; i++) {
if (!seenSpace) {
if (statm[i] == ' ') {
seenSpace = true;
}
}
else {
if (statm[i] == ' ') {
break;
}
else {
result = result * 10 + (statm[i] - '0');
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment