diff options
author | Hector Dearman <hjd@google.com> | 2018-06-20 10:57:06 +0100 |
---|---|---|
committer | Primiano Tucci <primiano@google.com> | 2018-06-20 15:14:06 +0100 |
commit | c5e18407c277ca75b854b4416c70d23dc2c6a90e (patch) | |
tree | 4c03e4372ba0c8cc83880b65bb608d16442753e3 | |
parent | 05cd4b895e5d78ef82448cb9bf71fba6b1ad48ae (diff) | |
download | perfetto-pie-b4s4-release.tar.gz |
traced_probes: Fix clock bugandroid-9.0.0_r47android-9.0.0_r46android-9.0.0_r45android-9.0.0_r44android-9.0.0_r43android-9.0.0_r42android-9.0.0_r41android-9.0.0_r40android-9.0.0_r39android-9.0.0_r38android-9.0.0_r37android-9.0.0_r36pie-qpr3-s1-releasepie-qpr3-releasepie-qpr3-b-releasepie-b4s4-releasepie-b4s4-dev
There was a bug when parsing the list of available clocks from
/d/tracing/trace_clock.
The contents of /d/tracing/trace_clock looks like:
uptime perf mono mono_raw boot\n
We acidentally included the newline in the name of the final clock when
reading. This means (if boot is unfortunate enough to be the last clock
listed) we fail to set the boot clock (since "boot" != "boot\n").
Fix the parsing of trace_clock to discount the newline.
Bug: 110356412
Change-Id: I5160637efec69844fe75f8e705d02a7c486ae990
Merged-In: I5160637efec69844fe75f8e705d02a7c486ae990
(cherry picked from commit 22dac14815a58d00ea87a0013bb638c703843f11)
-rw-r--r-- | src/ftrace_reader/ftrace_procfs.cc | 2 | ||||
-rw-r--r-- | src/ftrace_reader/ftrace_procfs_unittest.cc | 36 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/ftrace_reader/ftrace_procfs.cc b/src/ftrace_reader/ftrace_procfs.cc index 70aa050e0..bcc255748 100644 --- a/src/ftrace_reader/ftrace_procfs.cc +++ b/src/ftrace_reader/ftrace_procfs.cc @@ -170,6 +170,8 @@ std::set<std::string> FtraceProcfs::AvailableClocks() { end = s.find(' ', start); if (end == std::string::npos) end = s.size(); + while (end > start && s[end - 1] == '\n') + end--; if (start == end) break; diff --git a/src/ftrace_reader/ftrace_procfs_unittest.cc b/src/ftrace_reader/ftrace_procfs_unittest.cc index bccf2e052..6c86339dc 100644 --- a/src/ftrace_reader/ftrace_procfs_unittest.cc +++ b/src/ftrace_reader/ftrace_procfs_unittest.cc @@ -56,8 +56,44 @@ TEST(FtraceProcfsTest, ParseAvailableClocks) { EXPECT_THAT(ftrace.GetClock(), "global"); EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("local global [boot]")); + EXPECT_THAT(ftrace.GetClock(), "boot"); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) .WillOnce(Return("")); EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty()); + + // trace_clock text may end in a new line: + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("[local] global boot\n")); + EXPECT_THAT(ftrace.AvailableClocks(), + UnorderedElementsAre("local", "global", "boot")); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("local global [boot]\n")); + EXPECT_THAT(ftrace.AvailableClocks(), + UnorderedElementsAre("local", "global", "boot")); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("local global [boot]\n")); + EXPECT_THAT(ftrace.GetClock(), "boot"); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("\n")); + EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty()); + + // We should handle many newlines (just in case): + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("local global [boot]\n\n\n")); + EXPECT_THAT(ftrace.GetClock(), "boot"); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("local global [boot]\n\n")); + EXPECT_THAT(ftrace.GetClock(), "boot"); + + EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock")) + .WillOnce(Return("\n\n\n\n")); + EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty()); } } // namespace |