TEST(stat_cmd, group_option) {
ASSERT_TRUE(
StatCmd()->Run({"--group", "cpu-cycles,cpu-clock", "sleep", "1"}));
- ASSERT_TRUE(StatCmd()->Run({"--group", "cpu-cycles,cpu-clock", "--group",
- "cpu-cycles:u,cpu-clock:u", "--group",
- "cpu-cycles:k,cpu-clock:k", "sleep", "1"}));
+ ASSERT_TRUE(StatCmd()->Run({"--group", "cpu-cycles,instructions", "--group",
+ "cpu-cycles:u,instructions:u", "--group",
+ "cpu-cycles:k,instructions:k", "sleep", "1"}));
}
TEST(stat_cmd, auto_generated_summary) {
TemporaryFile tmp_file;
- ASSERT_TRUE(StatCmd()->Run({"--group", "cpu-clock:u,cpu-clock:k", "-o",
+ ASSERT_TRUE(StatCmd()->Run({"--group", "instructions:u,instructions:k", "-o",
tmp_file.path, "sleep", "1"}));
std::string s;
ASSERT_TRUE(android::base::ReadFileToString(tmp_file.path, &s));
- size_t pos = s.find("cpu-clock:u");
+ size_t pos = s.find("instructions:u");
ASSERT_NE(s.npos, pos);
- pos = s.find("cpu-clock:k", pos);
+ pos = s.find("instructions:k", pos);
ASSERT_NE(s.npos, pos);
- pos += strlen("cpu-clock:k");
- // Check if the summary of cpu-clock is generated.
- ASSERT_NE(s.npos, s.find("cpu-clock", pos));
+ pos += strlen("instructions:k");
+ // Check if the summary of instructions is generated.
+ ASSERT_NE(s.npos, s.find("instructions", pos));
}
TEST(stat_cmd, duration_option) {
StatCmd()->Run({"--duration", "1.2", "-p", std::to_string(getpid())}));
ASSERT_TRUE(StatCmd()->Run({"--duration", "1", "sleep", "2"}));
}
+
+TEST(stat_cmd, no_modifier_for_clock_events) {
+ for (const std::string& e : {"cpu-clock", "task-clock"}) {
+ for (const std::string& m : {"u", "k"}) {
+ ASSERT_FALSE(StatCmd()->Run({"-e", e + ":" + m, "sleep", "0.1"}))
+ << "event " << e << ":" << m;
+ }
+ }
+}
if (event_type == nullptr) {
return false;
}
+ if (for_stat_cmd_) {
+ if (event_type->event_type.name == "cpu-clock" ||
+ event_type->event_type.name == "task-clock") {
+ if (event_type->exclude_user || event_type->exclude_kernel) {
+ LOG(ERROR) << "Modifier u and modifier k used in event type "
+ << event_type->event_type.name
+ << " are not supported by the kernel.";
+ return false;
+ }
+ }
+ }
selection->event_type_modifier = *event_type;
selection->event_attr = CreateDefaultPerfEventAttr(event_type->event_type);
selection->event_attr.exclude_user = event_type->exclude_user;