-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.c
47 lines (38 loc) · 1.13 KB
/
process.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "process.h"
Process fetchData(char *package) {
Process data = {0};
// Get Memory data
FILE *fp;
char buf[128];
char *cmd_adb = (char *) "adb shell dumpsys meminfo ";
char *cmd = (char *) malloc(1 + strlen(cmd_adb) + strlen(package));
strcpy(cmd, cmd_adb);
strcat(cmd, package);
if ((fp = popen(cmd, "r")) == NULL) {
printf("Error opening pipe!\n");
exit(EXIT_FAILURE);
}
while (fgets(buf, 128, fp) != NULL) {
// Print ADB Output
// printf("OUTPUT: %s", buf);
char *s;
if ((s = strstr(buf, "TOTAL")) != NULL) {
sscanf(s+6,"%*d %*d %*d %*d %d %d %d", &data.mem_total, &data.mem_alloc, &data.mem_free);
break;
}
}
if(pclose(fp)) {
// Command exited with error status
printf("Please ensure the android-sdk is installed and adb can detect your device.\n");
printf("\n");
printf("Use --help flag for usage information");
exit(EXIT_FAILURE);
}
// Get CPU data
// TODO
free(cmd);
return data;
}