gs-common: dumpstate: Rewrite dump_pixel_metrics to cpp

Test: adb bugreport
Bug: 279486693
Change-Id: Ia1611db82440e2a1a522269b363d8931b08f0fe5
Signed-off-by: Ziyi Cui <ziyic@google.com>
diff --git a/pixel_metrics/Android.bp b/pixel_metrics/Android.bp
index 3ad3ff4..04d83f3 100644
--- a/pixel_metrics/Android.bp
+++ b/pixel_metrics/Android.bp
@@ -2,9 +2,19 @@
     default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-sh_binary {
-    name: "dump_pixel_metrics.sh",
-    src: "dump_pixel_metrics.sh",
+cc_binary {
+    name: "dump_pixel_metrics",
+    srcs: ["dump_pixel_metrics.cpp"],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+    shared_libs: [
+        "libbase",
+	    "libdump",
+	    "liblog",
+    ],
     vendor: true,
-    sub_dir: "dump",
+    relative_install_path: "dump",
 }
diff --git a/pixel_metrics/dump_pixel_metrics.cpp b/pixel_metrics/dump_pixel_metrics.cpp
new file mode 100644
index 0000000..9a8f6e7
--- /dev/null
+++ b/pixel_metrics/dump_pixel_metrics.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <dump/pixel_dump.h>
+#include <android-base/file.h>
+
+
+int main() {
+    setbuf(stdout, NULL);
+    dumpFileContent("Long running IRQ metrics", "/sys/kernel/metrics/irq/long_irq_metrics");
+    dumpFileContent("Resume latency metrics", "/sys/kernel/metrics/resume_latency/resume_latency_metrics");
+    return 0;
+}
+
diff --git a/pixel_metrics/dump_pixel_metrics.sh b/pixel_metrics/dump_pixel_metrics.sh
deleted file mode 100644
index 0c6e2c2..0000000
--- a/pixel_metrics/dump_pixel_metrics.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/vendor/bin/sh
-echo "Long running IRQ metrics"
-cat /sys/kernel/metrics/irq/long_irq_metrics
-echo "Resume latency metrics"
-cat /sys/kernel/metrics/resume_latency/resume_latency_metrics
-echo "Temperature Residency Metrics:"
-cat /sys/kernel/metrics/temp_residency/temp_residency_all/stats
diff --git a/pixel_metrics/pixel_metrics.mk b/pixel_metrics/pixel_metrics.mk
index 41e027d..736ddf3 100644
--- a/pixel_metrics/pixel_metrics.mk
+++ b/pixel_metrics/pixel_metrics.mk
@@ -1,3 +1,3 @@
 BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/pixel_metrics/sepolicy
 
-PRODUCT_PACKAGES += dump_pixel_metrics.sh
+PRODUCT_PACKAGES += dump_pixel_metrics
diff --git a/pixel_metrics/sepolicy/dump_pixel_metrics.te b/pixel_metrics/sepolicy/dump_pixel_metrics.te
index 681670e..903a8e3 100644
--- a/pixel_metrics/sepolicy/dump_pixel_metrics.te
+++ b/pixel_metrics/sepolicy/dump_pixel_metrics.te
@@ -2,4 +2,4 @@
 
 #vendor-metrics
 r_dir_file(dump_pixel_metrics, sysfs_vendor_metrics)
-allow dump_pixel_metrics vendor_toolbox_exec:file execute_no_trans;
+allow dump_pixel_metrics vendor_dumpsys:file execute_no_trans;
diff --git a/pixel_metrics/sepolicy/device.te b/pixel_metrics/sepolicy/file.te
similarity index 100%
rename from pixel_metrics/sepolicy/device.te
rename to pixel_metrics/sepolicy/file.te
diff --git a/pixel_metrics/sepolicy/file_contexts b/pixel_metrics/sepolicy/file_contexts
index 1b5b11f..966055f 100644
--- a/pixel_metrics/sepolicy/file_contexts
+++ b/pixel_metrics/sepolicy/file_contexts
@@ -1 +1 @@
-/vendor/bin/dump/dump_pixel_metrics\.sh      u:object_r:dump_pixel_metrics_exec:s0
+/vendor/bin/dump/dump_pixel_metrics      u:object_r:dump_pixel_metrics_exec:s0