xref: /aosp_15_r20/system/extras/cpu_loads/pss.cpp (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1*288bf522SAndroid Build Coastguard Worker #include <arpa/inet.h>
2*288bf522SAndroid Build Coastguard Worker #include <cutils/sockets.h>
3*288bf522SAndroid Build Coastguard Worker #include <fcntl.h>
4*288bf522SAndroid Build Coastguard Worker #include <hardware/gralloc.h>
5*288bf522SAndroid Build Coastguard Worker #include <sys/stat.h>
6*288bf522SAndroid Build Coastguard Worker #include <sys/wait.h>
7*288bf522SAndroid Build Coastguard Worker #include <unistd.h>
8*288bf522SAndroid Build Coastguard Worker #include <algorithm>
9*288bf522SAndroid Build Coastguard Worker #include <chrono>
10*288bf522SAndroid Build Coastguard Worker #include <fstream>
11*288bf522SAndroid Build Coastguard Worker #include <iostream>
12*288bf522SAndroid Build Coastguard Worker #include <numeric>
13*288bf522SAndroid Build Coastguard Worker #include <string>
14*288bf522SAndroid Build Coastguard Worker #include <tuple>
15*288bf522SAndroid Build Coastguard Worker #include <vector>
16*288bf522SAndroid Build Coastguard Worker 
17*288bf522SAndroid Build Coastguard Worker #include <android-base/stringprintf.h>
18*288bf522SAndroid Build Coastguard Worker #include <meminfo/procmeminfo.h>
19*288bf522SAndroid Build Coastguard Worker 
20*288bf522SAndroid Build Coastguard Worker using namespace std;
21*288bf522SAndroid Build Coastguard Worker 
22*288bf522SAndroid Build Coastguard Worker #define BUFFER_SIZE (1024 * 1024 * 1024)
23*288bf522SAndroid Build Coastguard Worker 
main(int,char **)24*288bf522SAndroid Build Coastguard Worker int main(int, char**) {
25*288bf522SAndroid Build Coastguard Worker     // waste a bunch of memory
26*288bf522SAndroid Build Coastguard Worker     void* src = malloc(BUFFER_SIZE);
27*288bf522SAndroid Build Coastguard Worker     for (size_t i = 0; i < BUFFER_SIZE; i++) {
28*288bf522SAndroid Build Coastguard Worker         ((char*)src)[i] = (char)i;
29*288bf522SAndroid Build Coastguard Worker     }
30*288bf522SAndroid Build Coastguard Worker     void* dst = malloc(BUFFER_SIZE);
31*288bf522SAndroid Build Coastguard Worker     memcpy(dst, src, BUFFER_SIZE);
32*288bf522SAndroid Build Coastguard Worker 
33*288bf522SAndroid Build Coastguard Worker     uint64_t pss;
34*288bf522SAndroid Build Coastguard Worker     // should always return true
35*288bf522SAndroid Build Coastguard Worker     std::string pid_path = android::base::StringPrintf("/proc/%d/smaps", getpid());
36*288bf522SAndroid Build Coastguard Worker     while (android::meminfo::SmapsOrRollupPssFromFile(pid_path, &pss))
37*288bf522SAndroid Build Coastguard Worker         ;
38*288bf522SAndroid Build Coastguard Worker 
39*288bf522SAndroid Build Coastguard Worker     return 0;
40*288bf522SAndroid Build Coastguard Worker }
41