Update Indexes of parsing /proc/pid/stat file
Incorrect assumption that Split() utility function combined the first
and second section of the /proc/pid/stat file has caused incorrect
metrics to be exported by the daemon.
Fixing the indexes to match up
Tested:
Queried a daemon's dbus object and matched it up with its stat file
and ensured that all the metrics are valid and correct.
Change-Id: I5d2ab47c4cac32282c5605e10ea84043d7063253
Signed-off-by: Edward Lee <edwarddl@google.com>
diff --git a/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch b/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
index d4e871f..37c3268 100644
--- a/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
+++ b/recipes-google/metric-collector/metric-collector/0002-Metric-Collection-Daemon.patch
@@ -80,7 +80,7 @@
.gitignore | 1 +
meson.build | 1 +
metric-collection-daemon | 1 +
- .../metric-collection-daemon/daemon.cpp | 220 ++++++++++
+ .../metric-collection-daemon/daemon.cpp | 219 ++++++++++
.../metric-collection-daemon/daemon.hpp | 55 +++
.../metric-collection-daemon/meson.build | 58 +++
.../metricCollector.cpp | 392 ++++++++++++++++++
@@ -90,7 +90,7 @@
subprojects/metric-collection-daemon/port.hpp | 64 +++
.../metric-collection-daemon/utils.cpp | 179 ++++++++
.../metric-collection-daemon/utils.hpp | 35 ++
- 13 files changed, 1293 insertions(+)
+ 13 files changed, 1292 insertions(+)
create mode 120000 metric-collection-daemon
create mode 100644 subprojects/metric-collection-daemon/daemon.cpp
create mode 100644 subprojects/metric-collection-daemon/daemon.hpp
@@ -137,10 +137,10 @@
\ No newline at end of file
diff --git a/subprojects/metric-collection-daemon/daemon.cpp b/subprojects/metric-collection-daemon/daemon.cpp
new file mode 100644
-index 0000000..74056d3
+index 0000000..847f061
--- /dev/null
+++ b/subprojects/metric-collection-daemon/daemon.cpp
-@@ -0,0 +1,220 @@
+@@ -0,0 +1,219 @@
+#include "daemon.hpp"
+
+#include "utils.hpp"
@@ -242,25 +242,24 @@
+
+ const float invTicksPerSec = 1.0f / static_cast<float>(ticksPerSec);
+
-+ // In the parse proc file (split combines first 2 elements of proc
-+ // file): Index 12: utime Index 13: stime Index 22: rss Source:
-+ // https://man7.org/linux/man-pages/man5/proc.5.html
++ // Index 13: utime Index 14: stime Index 23: rss
++ // Source: https://man7.org/linux/man-pages/man5/proc.5.html
+ std::vector<std::string> parsedProcFile = split(processStats, ' ');
+
+ // Sometimes the file cant be opened due to kernel processing.
-+ if (parsedProcFile.size() < 23) {
++ if (parsedProcFile.size() < 24) {
+ return;
+ }
+
+ // Add utime, stime
-+ size_t utimeTicks = toSizeT(parsedProcFile.at(12));
-+ size_t stimeTicks = toSizeT(parsedProcFile.at(13));
++ size_t utimeTicks = toSizeT(parsedProcFile.at(13));
++ size_t stimeTicks = toSizeT(parsedProcFile.at(14));
+
+ userSeconds = static_cast<double>(utimeTicks) * invTicksPerSec;
+ kernelSeconds = static_cast<double>(stimeTicks) * invTicksPerSec;
+
+ // The RSS here is in sets of pages. Each page is 4KB.
-+ memoryUsage = toSizeT(parsedProcFile.at(22)) * PAGE_SIZE;
++ memoryUsage = toSizeT(parsedProcFile.at(23)) * PAGE_SIZE;
+
+ metrics->set_property("KernelTimeSeconds", kernelSeconds);
+ metrics->set_property("UserTimeSeconds", userSeconds);
@@ -1487,5 +1486,5 @@
+
+std::optional<std::string> getPortIdByNum(const int portNum);
--
-2.40.0.634.g4ca3ef3211-goog
+2.41.0.585.gd2178a4bd4-goog