diff --git a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-arm64-v8a b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-arm64-v8a index 18ef6305..e4aa5bea 100755 Binary files a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-arm64-v8a and b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-arm64-v8a differ diff --git a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-armeabi-v7a b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-armeabi-v7a index f5f2dc7d..8c86036e 100755 Binary files a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-armeabi-v7a and b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-armeabi-v7a differ diff --git a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86 b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86 index c26fc6ff..b808c1c4 100755 Binary files a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86 and b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86 differ diff --git a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86_64 b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86_64 index 6b8f4398..a515fad8 100755 Binary files a/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86_64 and b/packages/platforms/android/cpp-profiler/bin/BAMPerfProfiler-x86_64 differ diff --git a/packages/platforms/android/cpp-profiler/src/main.cpp b/packages/platforms/android/cpp-profiler/src/main.cpp index 6796eb18..4aa1886e 100644 --- a/packages/platforms/android/cpp-profiler/src/main.cpp +++ b/packages/platforms/android/cpp-profiler/src/main.cpp @@ -40,40 +40,47 @@ class PidClosedError : public std::runtime_error : std::runtime_error(message) {} }; -void printCpuStats(string pid) +void printCpuStats(std::vector pids) { - string path = "/proc/" + pid + "/task"; - - if (!fs::exists(path)) + for (string pid : pids) { - throw PidClosedError("Directory does not exist: " + path); - } + string path = "/proc/" + pid + "/task"; - for (const auto &entry : fs::directory_iterator(path)) - { - string subProcessPath = entry.path().string() + "/stat"; - readFile(subProcessPath); + if (!fs::exists(path)) + { + throw PidClosedError("Directory does not exist: " + path); + } + + for (const auto &entry : fs::directory_iterator(path)) + { + string subProcessPath = entry.path().string() + "/stat"; + readFile(subProcessPath); + } } } -void printMemoryStats(string pid) +void printMemoryStats(std::vector pids) { - string memoryFilePath = "/proc/" + pid + "/statm"; - readFile(memoryFilePath); + for (string pid : pids) + { + string memoryFilePath = "/proc/" + pid + "/statm"; + readFile(memoryFilePath); + } } -long long printPerformanceMeasure(string pid) +long long printPerformanceMeasure(std::vector pids) { auto start = std::chrono::system_clock::now(); string separator = "=SEPARATOR="; log("=START MEASURE="); - log(pid); + // Log the first pid as the main pid + log(pids[0]); log(separator); - printCpuStats(pid); + printCpuStats(pids); auto cpuEnd = std::chrono::system_clock::now(); log(separator); - printMemoryStats(pid); + printMemoryStats(pids); auto memoryEnd = std::chrono::system_clock::now(); log(separator); // TODO handle ATrace not available on OS @@ -100,15 +107,15 @@ long long printPerformanceMeasure(string pid) return totalDuration.count(); } -std::string pidOf(string bundleId) +std::vector pidOf(string bundleId) { auto result = executeCommand("pidof " + bundleId); - return result.substr(0, result.find_first_of("\n")); + return split(result, ' '); } void pollPerformanceMeasures(std::string bundleId, int interval) { - string pid = ""; + std::vector pids; // We read atrace lines before the app is started // since it can take a bit of time to start and clear the traceOutputPath @@ -118,10 +125,10 @@ void pollPerformanceMeasures(std::string bundleId, int interval) cout << "Waiting for process to start..." << endl; - while (pid == "") + while (pids.empty()) { clearATraceLines(); - pid = pidOf(bundleId); + pids = pidOf(bundleId); std::this_thread::sleep_for(std::chrono::milliseconds(50)); } @@ -129,13 +136,13 @@ void pollPerformanceMeasures(std::string bundleId, int interval) { while (true) { - auto duration = printPerformanceMeasure(pid); + auto duration = printPerformanceMeasure(pids); std::this_thread::sleep_for(std::chrono::milliseconds(interval - duration)); } } catch (const PidClosedError &e) { - cerr << "CPP_ERROR_MAIN_PID_CLOSED " + pid << endl; + cerr << "CPP_ERROR_MAIN_PID_CLOSED " << e.what() << endl; pollPerformanceMeasures(bundleId, interval); return; } @@ -166,7 +173,9 @@ int main(int argc, char **argv) } else if (methodName == "printPerformanceMeasure") { - printPerformanceMeasure(argv[2]); + std::vector pids; + pids.push_back(argv[2]); + printPerformanceMeasure(pids); } else if (methodName == "printCpuClockTick") { diff --git a/packages/platforms/android/cpp-profiler/src/utils.cpp b/packages/platforms/android/cpp-profiler/src/utils.cpp index caab8147..3a0d5472 100644 --- a/packages/platforms/android/cpp-profiler/src/utils.cpp +++ b/packages/platforms/android/cpp-profiler/src/utils.cpp @@ -37,3 +37,23 @@ std::string executeCommand(std::string command) } return result; } + +std::vector split(const std::string &str, char delimiter) +{ + std::vector result; + std::string currentResult = ""; + for (char c : str) + { + if (c == delimiter || c == '\n') + { + result.push_back(currentResult); + currentResult = ""; + } + else + { + currentResult += c; + } + } + + return result; +} diff --git a/packages/platforms/android/cpp-profiler/src/utils.h b/packages/platforms/android/cpp-profiler/src/utils.h index 127feafc..abda0cc5 100644 --- a/packages/platforms/android/cpp-profiler/src/utils.h +++ b/packages/platforms/android/cpp-profiler/src/utils.h @@ -6,5 +6,6 @@ void log(const std::string &msg); void logTimestamp(); std::string executeCommand(std::string command); +std::vector split(const std::string &str, char delimiter); #endif /* UTILS_H */ diff --git a/packages/platforms/android/src/commands/ram/pollRamUsage.ts b/packages/platforms/android/src/commands/ram/pollRamUsage.ts index 770960be..02b70d71 100644 --- a/packages/platforms/android/src/commands/ram/pollRamUsage.ts +++ b/packages/platforms/android/src/commands/ram/pollRamUsage.ts @@ -3,5 +3,11 @@ import { getRAMPageSize } from "../cppProfiler"; const BYTES_PER_MB = 1024 * 1024; export const processOutput = (result: string) => { - return (parseInt(result.split(" ")[1], 10) * getRAMPageSize()) / BYTES_PER_MB; + const lines = result.split("\n"); + let total = 0; + + for (const line of lines) { + total += (parseInt(line.split(" ")[1], 10) * getRAMPageSize()) / BYTES_PER_MB; + } + return total; };