-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmeminfo.cpp
More file actions
50 lines (40 loc) · 1.05 KB
/
meminfo.cpp
File metadata and controls
50 lines (40 loc) · 1.05 KB
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
48
49
50
#include "meminfo.h"
#include <array>
#include <iostream>
std::string exec(std::string cmd)
{
std::array<char, 128> buffer;
std::string result;
auto pipe = popen(cmd.c_str(), "r"); // get rid of shared_ptr
if (!pipe)
throw std::runtime_error("popen() failed!");
while (!feof(pipe))
{
if (fgets(buffer.data(), 128, pipe) != nullptr)
result += buffer.data();
}
auto rc = pclose(pipe);
if (rc == EXIT_SUCCESS)
{ // == 0
}
else if (rc == EXIT_FAILURE)
{ // EXIT_FAILURE is not used by all programs, maybe needs some adaptation.
}
return result;
}
std::string currentOutput;
std::string getCurrentMeminfoResult()
{
return currentOutput;
}
void pollMeminfo(std::string bundleId)
{
while (true)
{
auto start = std::chrono::system_clock::now();
currentOutput = exec("dumpsys meminfo " + bundleId);
auto end = std::chrono::system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "MEMINFO EXEC TIME: " << duration.count() << std::endl;
}
}