atrace: Enable a 'record-tgid' option for printing TGID of the task 58/288958/1
authorSung-hun Kim <sfoon.kim@samsung.com>
Mon, 27 Feb 2023 03:02:21 +0000 (12:02 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Mon, 27 Feb 2023 03:02:21 +0000 (12:02 +0900)
After Linux kernel version 4.13, an option should be set to print
TGID of tasks. This patch enables this option.

Change-Id: I22aaa91f0c3d8c43e83dee039733318b744f9a81
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
atrace/atrace.cpp

index ae2a0b7dd4040c126d0b27a83007ec198583f262..a465be0494001bdf99ded184f3d2258d397e40d7 100755 (executable)
@@ -221,6 +221,9 @@ static const char* k_currentTracerPath =
 static const char* k_printTgidPath =
     "/sys/kernel/debug/tracing/options/print-tgid";
 
+static const char* k_recordTgidPath =
+    "/sys/kernel/debug/tracing/options/record-tgid";
+
 static const char* k_funcgraphAbsTimePath =
     "/sys/kernel/debug/tracing/options/funcgraph-abstime";
 
@@ -431,6 +434,18 @@ static bool setPrintTgidEnableIfPresent(bool enable)
     return true;
 }
 
+// Since Linux kernel 4.13, an option is added for printing
+// recorded TGID, namely 'record-tgid'.
+// In order to print TGID of tasks, atrace should enable
+// this option.
+static bool setRecordTgidEnableIfPresent(bool enable)
+{
+    if (fileExists(k_recordTgidPath)) {
+        return setKernelOptionEnable(k_recordTgidPath, enable);
+    }
+    return true;
+}
+
 static bool getBootupTagStr(char* bootupTagStr, int strSize)
 {
     if(fileExists(BOOTUP_TRACE)) {
@@ -605,6 +620,7 @@ static bool setUpTrace()
         ok &= setKernelTraceFuncs(g_kernelTraceFuncs);
     }
     ok &= setPrintTgidEnableIfPresent(true);
+    ok &= setRecordTgidEnableIfPresent(true);
 
     // Set up the tags property.
     uint64_t tags = 0;
@@ -675,6 +691,7 @@ static void cleanUpTrace()
     setTraceBufferSizeKB(1);
     setBestClock(false);
     setPrintTgidEnableIfPresent(false);
+    setRecordTgidEnableIfPresent(false);
     setKernelTraceFuncs(nullptr);
 }