trace_processor: don't print extra new line in print events
If print event has a new line, strip it before printing to prevent
double new lines.
Bug: 126448611
Change-Id: I36dbcd692a157d9756caeeedc19667c98fa0872f
diff --git a/src/trace_processor/raw_table.cc b/src/trace_processor/raw_table.cc
index 62629e5..76423d8 100644
--- a/src/trace_processor/raw_table.cc
+++ b/src/trace_processor/raw_table.cc
@@ -180,6 +180,19 @@
writer->AppendString(" transaction=");
write_value_at_index(BTR::kDebugIdFieldNumber - 1, write_value);
return;
+ } else if (event_name == "print") {
+ using P = protos::PrintFtraceEvent;
+ write_arg(P::kIpFieldNumber - 1, write_value);
+ write_arg(P::kBufFieldNumber - 1, [this, writer](const Variadic& value) {
+ const auto& str = storage_->GetString(value.string_value);
+
+ // If the last character is a newline in a print, just drop it.
+ auto chars_to_print = str.size() > 0 && str[str.size() - 1] == '\n'
+ ? str.size() - 1
+ : str.size();
+ writer->AppendString(str.c_str(), chars_to_print);
+ });
+ return;
}
uint32_t arg = 0;
@@ -192,7 +205,7 @@
int argc,
sqlite3_value** argv) {
if (argc != 1 || sqlite3_value_type(argv[0]) != SQLITE_INTEGER) {
- sqlite3_result_error(ctx, "Usage: systrace(id)", -1);
+ sqlite3_result_error(ctx, "Usage: to_ftrace(id)", -1);
return;
}
RowId row_id = sqlite3_value_int64(argv[0]);
diff --git a/src/trace_processor/trace_processor_shell.cc b/src/trace_processor/trace_processor_shell.cc
index 7895af5..58cfff7 100644
--- a/src/trace_processor/trace_processor_shell.cc
+++ b/src/trace_processor/trace_processor_shell.cc
@@ -539,7 +539,7 @@
}
if (!RunQueryAndPrintResult(queries, stdout)) {
- return false;
+ return 1;
}
// After this we can dump the database and exit if needed.
diff --git a/test/trace_processor/index b/test/trace_processor/index
index 286c1d2..ea03a0a 100644
--- a/test/trace_processor/index
+++ b/test/trace_processor/index
@@ -68,3 +68,8 @@
# Null printing
synth_1.py nulls.sql nulls.out
+
+
+# The below tests check the systrace conversion code in the raw table.
+# Print events
+../data/lmk_userspace.pb print_systrace.sql print_systrace_lmk_userspace.out
diff --git a/test/trace_processor/print_systrace.sql b/test/trace_processor/print_systrace.sql
new file mode 100644
index 0000000..ab5d87e
--- /dev/null
+++ b/test/trace_processor/print_systrace.sql
@@ -0,0 +1,2 @@
+SELECT to_ftrace(id)
+from raw;
diff --git a/test/trace_processor/print_systrace_lmk_userspace.out b/test/trace_processor/print_systrace_lmk_userspace.out
new file mode 100644
index 0000000..db225cd
--- /dev/null
+++ b/test/trace_processor/print_systrace_lmk_userspace.out
@@ -0,0 +1,9 @@
+"to_ftrace(id)"
+" -937 ( 937) [002] .... 732246.100696: print: ip=-532971597544 buf=C|937|kill_one_process|17924"
+" -937 ( 937) [002] .... 732246.101048: print: ip=-532971597544 buf=C|937|kill_one_process|0"
+" -937 ( 937) [002] .... 732246.180149: print: ip=-532971597544 buf=C|937|kill_one_process|21090"
+" -937 ( 937) [002] .... 732246.180405: print: ip=-532971597544 buf=C|937|kill_one_process|0"
+" -937 ( 937) [001] .... 732246.388596: print: ip=-532971597544 buf=C|937|kill_one_process|21120"
+" -937 ( 937) [001] .... 732246.388961: print: ip=-532971597544 buf=C|937|kill_one_process|0"
+" -937 ( 937) [002] .... 732246.415955: print: ip=-532971597544 buf=C|937|kill_one_process|21151"
+" -937 ( 937) [002] .... 732246.416207: print: ip=-532971597544 buf=C|937|kill_one_process|0"