| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 19 | #include <set> |
| 20 | #include <unordered_map> |
| 21 | |
| Yabin Cui | b1a885b | 2016-02-14 19:18:02 -0800 | [diff] [blame] | 22 | #include <android-base/file.h> |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 23 | #include <android-base/parseint.h> |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 24 | #include <android-base/strings.h> |
| Yabin Cui | c4d9ead | 2022-01-06 15:41:31 -0800 | [diff] [blame] | 25 | #include <android-base/test_utils.h> |
| Yabin Cui | b1a885b | 2016-02-14 19:18:02 -0800 | [diff] [blame] | 26 | |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 27 | #include "RegEx.h" |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 28 | #include "command.h" |
| Yabin Cui | b1a885b | 2016-02-14 19:18:02 -0800 | [diff] [blame] | 29 | #include "get_test_data.h" |
| Yabin Cui | 8f680f6 | 2016-03-18 18:47:43 -0700 | [diff] [blame] | 30 | #include "perf_regs.h" |
| Yabin Cui | b1a885b | 2016-02-14 19:18:02 -0800 | [diff] [blame] | 31 | #include "read_apk.h" |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 32 | #include "test_util.h" |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 33 | |
| Yabin Cui | acbdb24 | 2020-07-07 15:56:34 -0700 | [diff] [blame] | 34 | using namespace simpleperf; |
| 35 | |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 36 | static std::unique_ptr<Command> ReportCmd() { |
| 37 | return CreateCommandInstance("report"); |
| 38 | } |
| 39 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 40 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 41 | class ReportCommandTest : public ::testing::Test { |
| 42 | protected: |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 43 | void Report(const std::string& perf_data, |
| Wei-Ning Huang | b3f184f | 2024-03-22 00:49:18 +0800 | [diff] [blame] | 44 | const std::vector<std::string>& add_args = std::vector<std::string>(), |
| 45 | bool with_symfs = true) { |
| 46 | ReportRaw(GetTestData(perf_data), add_args, with_symfs); |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 47 | } |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 48 | |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 49 | void ReportRaw(const std::string& perf_data, |
| Wei-Ning Huang | b3f184f | 2024-03-22 00:49:18 +0800 | [diff] [blame] | 50 | const std::vector<std::string>& add_args = std::vector<std::string>(), |
| 51 | bool with_symfs = true) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 52 | success = false; |
| Yabin Cui | f560a6f | 2016-12-14 17:43:26 -0800 | [diff] [blame] | 53 | TemporaryFile tmp_file; |
| Wei-Ning Huang | b3f184f | 2024-03-22 00:49:18 +0800 | [diff] [blame] | 54 | std::vector<std::string> args = {"-i", perf_data, "-o", tmp_file.path}; |
| 55 | |
| 56 | if (with_symfs) { |
| 57 | args.emplace_back("--symfs"); |
| 58 | args.emplace_back(GetTestDataDir()); |
| 59 | } |
| 60 | |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 61 | args.insert(args.end(), add_args.begin(), add_args.end()); |
| 62 | ASSERT_TRUE(ReportCmd()->Run(args)); |
| 63 | ASSERT_TRUE(android::base::ReadFileToString(tmp_file.path, &content)); |
| 64 | ASSERT_TRUE(!content.empty()); |
| 65 | std::vector<std::string> raw_lines = android::base::Split(content, "\n"); |
| 66 | lines.clear(); |
| 67 | for (const auto& line : raw_lines) { |
| 68 | std::string s = android::base::Trim(line); |
| 69 | if (!s.empty()) { |
| 70 | lines.push_back(s); |
| 71 | } |
| 72 | } |
| 73 | ASSERT_GE(lines.size(), 2u); |
| 74 | success = true; |
| 75 | } |
| 76 | |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 77 | size_t GetSampleCount() { |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 78 | auto regex = RegEx::Create(R"(Samples: (\d+))"); |
| 79 | auto match = regex->SearchAll(content); |
| 80 | if (match->IsValid()) { |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 81 | size_t count; |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 82 | if (android::base::ParseUint(match->GetField(1), &count)) { |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 83 | return count; |
| 84 | } |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 89 | std::string content; |
| 90 | std::vector<std::string> lines; |
| 91 | bool success; |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 94 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 95 | TEST_F(ReportCommandTest, no_option) { |
| 96 | Report(PERF_DATA); |
| 97 | ASSERT_TRUE(success); |
| 98 | ASSERT_NE(content.find("GlobalFunc"), std::string::npos); |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 101 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 0540053 | 2016-03-17 21:18:53 -0700 | [diff] [blame] | 102 | TEST_F(ReportCommandTest, report_symbol_from_elf_file_with_mini_debug_info) { |
| 103 | Report(PERF_DATA_WITH_MINI_DEBUG_INFO); |
| 104 | ASSERT_TRUE(success); |
| 105 | ASSERT_NE(content.find("GlobalFunc"), std::string::npos); |
| 106 | } |
| 107 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 108 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 109 | TEST_F(ReportCommandTest, sort_option_pid) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 110 | Report(PERF_DATA, {"--sort", "pid"}); |
| 111 | ASSERT_TRUE(success); |
| 112 | size_t line_index = 0; |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 113 | while (line_index < lines.size() && lines[line_index].find("Pid") == std::string::npos) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 114 | line_index++; |
| 115 | } |
| 116 | ASSERT_LT(line_index + 2, lines.size()); |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 119 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 120 | TEST_F(ReportCommandTest, sort_option_more_than_one) { |
| 121 | Report(PERF_DATA, {"--sort", "comm,pid,dso,symbol"}); |
| 122 | ASSERT_TRUE(success); |
| 123 | size_t line_index = 0; |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 124 | while (line_index < lines.size() && lines[line_index].find("Overhead") == std::string::npos) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 125 | line_index++; |
| 126 | } |
| 127 | ASSERT_LT(line_index + 1, lines.size()); |
| 128 | ASSERT_NE(lines[line_index].find("Command"), std::string::npos); |
| 129 | ASSERT_NE(lines[line_index].find("Pid"), std::string::npos); |
| 130 | ASSERT_NE(lines[line_index].find("Shared Object"), std::string::npos); |
| 131 | ASSERT_NE(lines[line_index].find("Symbol"), std::string::npos); |
| 132 | ASSERT_EQ(lines[line_index].find("Tid"), std::string::npos); |
| Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 133 | } |
| Yabin Cui | 8a530e3 | 2015-06-23 20:42:01 -0700 | [diff] [blame] | 134 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 135 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | ecb9a30 | 2015-07-01 10:00:52 -0700 | [diff] [blame] | 136 | TEST_F(ReportCommandTest, children_option) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 137 | Report(CALLGRAPH_FP_PERF_DATA, {"--children", "--sort", "symbol"}); |
| 138 | ASSERT_TRUE(success); |
| 139 | std::unordered_map<std::string, std::pair<double, double>> map; |
| 140 | for (size_t i = 0; i < lines.size(); ++i) { |
| 141 | char name[1024]; |
| 142 | std::pair<double, double> pair; |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 143 | if (sscanf(lines[i].c_str(), "%lf%%%lf%%%s", &pair.first, &pair.second, name) == 3) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 144 | map.insert(std::make_pair(name, pair)); |
| 145 | } |
| 146 | } |
| 147 | ASSERT_NE(map.find("GlobalFunc"), map.end()); |
| 148 | ASSERT_NE(map.find("main"), map.end()); |
| 149 | auto func_pair = map["GlobalFunc"]; |
| 150 | auto main_pair = map["main"]; |
| 151 | ASSERT_GE(main_pair.first, func_pair.first); |
| 152 | ASSERT_GE(func_pair.first, func_pair.second); |
| 153 | ASSERT_GE(func_pair.second, main_pair.second); |
| 154 | } |
| 155 | |
| 156 | static bool CheckCalleeMode(std::vector<std::string>& lines) { |
| 157 | bool found = false; |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 158 | for (size_t i = 0; i + 1 < lines.size(); ++i) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 159 | if (lines[i].find("GlobalFunc") != std::string::npos && |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 160 | lines[i + 1].find("main") != std::string::npos) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 161 | found = true; |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | return found; |
| 166 | } |
| 167 | |
| 168 | static bool CheckCallerMode(std::vector<std::string>& lines) { |
| 169 | bool found = false; |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 170 | for (size_t i = 0; i + 1 < lines.size(); ++i) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 171 | if (lines[i].find("main") != std::string::npos && |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 172 | lines[i + 1].find("GlobalFunc") != std::string::npos) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 173 | found = true; |
| 174 | break; |
| 175 | } |
| 176 | } |
| 177 | return found; |
| Yabin Cui | ecb9a30 | 2015-07-01 10:00:52 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 180 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | ecb9a30 | 2015-07-01 10:00:52 -0700 | [diff] [blame] | 181 | TEST_F(ReportCommandTest, callgraph_option) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 182 | Report(CALLGRAPH_FP_PERF_DATA, {"-g"}); |
| 183 | ASSERT_TRUE(success); |
| Yabin Cui | 8a599d7 | 2016-07-21 18:32:53 -0700 | [diff] [blame] | 184 | ASSERT_TRUE(CheckCallerMode(lines)); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 185 | Report(CALLGRAPH_FP_PERF_DATA, {"-g", "callee"}); |
| 186 | ASSERT_TRUE(success); |
| 187 | ASSERT_TRUE(CheckCalleeMode(lines)); |
| 188 | Report(CALLGRAPH_FP_PERF_DATA, {"-g", "caller"}); |
| 189 | ASSERT_TRUE(success); |
| 190 | ASSERT_TRUE(CheckCallerMode(lines)); |
| 191 | } |
| 192 | |
| Yabin Cui | 767dd17 | 2016-06-02 21:02:43 -0700 | [diff] [blame] | 193 | static bool AllItemsWithString(std::vector<std::string>& lines, |
| 194 | const std::vector<std::string>& strs) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 195 | size_t line_index = 0; |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 196 | while (line_index < lines.size() && lines[line_index].find("Overhead") == std::string::npos) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 197 | line_index++; |
| 198 | } |
| 199 | if (line_index == lines.size() || line_index + 1 == lines.size()) { |
| 200 | return false; |
| 201 | } |
| 202 | line_index++; |
| 203 | for (; line_index < lines.size(); ++line_index) { |
| 204 | bool exist = false; |
| 205 | for (auto& s : strs) { |
| 206 | if (lines[line_index].find(s) != std::string::npos) { |
| 207 | exist = true; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | if (!exist) { |
| 212 | return false; |
| 213 | } |
| 214 | } |
| 215 | return true; |
| Yabin Cui | ecb9a30 | 2015-07-01 10:00:52 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 218 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 219 | TEST_F(ReportCommandTest, pid_filter_option) { |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 220 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid"}); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 221 | ASSERT_TRUE(success); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 222 | ASSERT_FALSE(AllItemsWithString(lines, {"17441"})); |
| 223 | ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17443"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 224 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--pids", "17441"}); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 225 | ASSERT_TRUE(success); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 226 | ASSERT_TRUE(AllItemsWithString(lines, {"17441"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 227 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--pids", "17441,17443"}); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 228 | ASSERT_TRUE(success); |
| 229 | ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17443"})); |
| 230 | |
| 231 | // Test that --pids option is not the same as --tids option. |
| 232 | // Thread 17445 and 17441 are in process 17441. |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 233 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--pids", "17441"}); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 234 | ASSERT_TRUE(success); |
| 235 | ASSERT_NE(content.find("17441"), std::string::npos); |
| 236 | ASSERT_NE(content.find("17445"), std::string::npos); |
| 237 | } |
| 238 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 239 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 240 | TEST_F(ReportCommandTest, wrong_pid_filter_option) { |
| 241 | ASSERT_EXIT( |
| 242 | { |
| 243 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--pids", "2,bogus"}); |
| 244 | exit(success ? 0 : 1); |
| 245 | }, |
| Yabin Cui | 1c6be75 | 2023-02-28 11:46:37 -0800 | [diff] [blame] | 246 | testing::ExitedWithCode(1), "invalid pid: bogus"); |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 249 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 250 | TEST_F(ReportCommandTest, tid_filter_option) { |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 251 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid"}); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 252 | ASSERT_TRUE(success); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 253 | ASSERT_FALSE(AllItemsWithString(lines, {"17441"})); |
| 254 | ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17445"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 255 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--tids", "17441"}); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 256 | ASSERT_TRUE(success); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 257 | ASSERT_TRUE(AllItemsWithString(lines, {"17441"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 258 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--tids", "17441,17445"}); |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 259 | ASSERT_TRUE(success); |
| 260 | ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17445"})); |
| 261 | } |
| 262 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 263 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 861f655 | 2016-08-08 14:42:25 -0700 | [diff] [blame] | 264 | TEST_F(ReportCommandTest, wrong_tid_filter_option) { |
| 265 | ASSERT_EXIT( |
| 266 | { |
| 267 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--tids", "2,bogus"}); |
| 268 | exit(success ? 0 : 1); |
| 269 | }, |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 270 | testing::ExitedWithCode(1), "Invalid tid 'bogus'"); |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 273 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 274 | TEST_F(ReportCommandTest, comm_filter_option) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 275 | Report(PERF_DATA, {"--sort", "comm"}); |
| 276 | ASSERT_TRUE(success); |
| 277 | ASSERT_FALSE(AllItemsWithString(lines, {"t1"})); |
| 278 | ASSERT_FALSE(AllItemsWithString(lines, {"t1", "t2"})); |
| 279 | Report(PERF_DATA, {"--sort", "comm", "--comms", "t1"}); |
| 280 | ASSERT_TRUE(success); |
| 281 | ASSERT_TRUE(AllItemsWithString(lines, {"t1"})); |
| 282 | Report(PERF_DATA, {"--sort", "comm", "--comms", "t1,t2"}); |
| 283 | ASSERT_TRUE(success); |
| 284 | ASSERT_TRUE(AllItemsWithString(lines, {"t1", "t2"})); |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 287 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 288 | TEST_F(ReportCommandTest, dso_filter_option) { |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 289 | Report(PERF_DATA, {"--sort", "dso"}); |
| 290 | ASSERT_TRUE(success); |
| 291 | ASSERT_FALSE(AllItemsWithString(lines, {"/t1"})); |
| 292 | ASSERT_FALSE(AllItemsWithString(lines, {"/t1", "/t2"})); |
| 293 | Report(PERF_DATA, {"--sort", "dso", "--dsos", "/t1"}); |
| 294 | ASSERT_TRUE(success); |
| 295 | ASSERT_TRUE(AllItemsWithString(lines, {"/t1"})); |
| 296 | Report(PERF_DATA, {"--sort", "dso", "--dsos", "/t1,/t2"}); |
| 297 | ASSERT_TRUE(success); |
| 298 | ASSERT_TRUE(AllItemsWithString(lines, {"/t1", "/t2"})); |
| Yabin Cui | 38e573e | 2015-08-06 11:25:09 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 301 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | f79fbd1 | 2016-07-06 12:26:13 -0700 | [diff] [blame] | 302 | TEST_F(ReportCommandTest, symbol_filter_option) { |
| 303 | Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol"}); |
| 304 | ASSERT_TRUE(success); |
| Yabin Cui | 05ef2ea | 2016-07-11 13:50:01 -0700 | [diff] [blame] | 305 | ASSERT_FALSE(AllItemsWithString(lines, {"func2(int, int)"})); |
| 306 | ASSERT_FALSE(AllItemsWithString(lines, {"main", "func2(int, int)"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 307 | Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol", "--symbols", "func2(int, int)"}); |
| Yabin Cui | f79fbd1 | 2016-07-06 12:26:13 -0700 | [diff] [blame] | 308 | ASSERT_TRUE(success); |
| Yabin Cui | 05ef2ea | 2016-07-11 13:50:01 -0700 | [diff] [blame] | 309 | ASSERT_TRUE(AllItemsWithString(lines, {"func2(int, int)"})); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 310 | Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol", "--symbols", "main;func2(int, int)"}); |
| Yabin Cui | f79fbd1 | 2016-07-06 12:26:13 -0700 | [diff] [blame] | 311 | ASSERT_TRUE(success); |
| Yabin Cui | 05ef2ea | 2016-07-11 13:50:01 -0700 | [diff] [blame] | 312 | ASSERT_TRUE(AllItemsWithString(lines, {"main", "func2(int, int)"})); |
| Yabin Cui | f79fbd1 | 2016-07-06 12:26:13 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 315 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 316 | TEST_F(ReportCommandTest, dso_symbol_filter_with_children_option) { |
| 317 | // dso and symbol filter should filter different layers of the callchain separately. |
| 318 | Report("perf_display_bitmaps.data", {"--dsos", "/apex/com.android.runtime/lib64/libart.so", |
| 319 | "--children", "--raw-period", "--sort", "dso"}); |
| 320 | ASSERT_TRUE(success); |
| 321 | ASSERT_NE(content.find("63500000 43250000 /apex/com.android.runtime/lib64/libart.so"), |
| 322 | std::string::npos); |
| 323 | |
| 324 | Report("perf_display_bitmaps.data", |
| 325 | {"--symbols", "MterpInvokeVirtual", "--children", "--raw-period", "--sort", "symbol"}); |
| 326 | ASSERT_TRUE(success); |
| 327 | ASSERT_NE(content.find("51500000 2500000 MterpInvokeVirtual"), std::string::npos); |
| 328 | } |
| 329 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 330 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 331 | TEST_F(ReportCommandTest, use_branch_address) { |
| 332 | Report(BRANCH_PERF_DATA, {"-b", "--sort", "symbol_from,symbol_to"}); |
| 333 | std::set<std::pair<std::string, std::string>> hit_set; |
| 334 | bool after_overhead = false; |
| 335 | for (const auto& line : lines) { |
| 336 | if (!after_overhead && line.find("Overhead") != std::string::npos) { |
| 337 | after_overhead = true; |
| 338 | } else if (after_overhead) { |
| 339 | char from[80]; |
| 340 | char to[80]; |
| 341 | if (sscanf(line.c_str(), "%*f%%%s%s", from, to) == 2) { |
| 342 | hit_set.insert(std::make_pair<std::string, std::string>(from, to)); |
| 343 | } |
| 344 | } |
| Yabin Cui | 8a530e3 | 2015-06-23 20:42:01 -0700 | [diff] [blame] | 345 | } |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 346 | ASSERT_NE(hit_set.find(std::make_pair<std::string, std::string>("GlobalFunc", "CalledFunc")), |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 347 | hit_set.end()); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 348 | ASSERT_NE(hit_set.find(std::make_pair<std::string, std::string>("CalledFunc", "GlobalFunc")), |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 349 | hit_set.end()); |
| Yabin Cui | 8a530e3 | 2015-06-23 20:42:01 -0700 | [diff] [blame] | 350 | } |
| Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 351 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 352 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 8f680f6 | 2016-03-18 18:47:43 -0700 | [diff] [blame] | 353 | TEST_F(ReportCommandTest, report_symbols_of_nativelib_in_apk) { |
| 354 | Report(NATIVELIB_IN_APK_PERF_DATA); |
| 355 | ASSERT_TRUE(success); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 356 | ASSERT_NE(content.find(GetUrlInApk(APK_FILE, NATIVELIB_IN_APK)), std::string::npos); |
| Yabin Cui | 8f680f6 | 2016-03-18 18:47:43 -0700 | [diff] [blame] | 357 | ASSERT_NE(content.find("Func2"), std::string::npos); |
| 358 | } |
| 359 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 360 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 2d6efe4 | 2016-04-01 20:22:35 -0700 | [diff] [blame] | 361 | TEST_F(ReportCommandTest, report_more_than_one_event_types) { |
| 362 | Report(PERF_DATA_WITH_TWO_EVENT_TYPES); |
| 363 | ASSERT_TRUE(success); |
| Yabin Cui | ada97db | 2017-02-23 15:54:11 -0800 | [diff] [blame] | 364 | size_t pos = 0; |
| 365 | ASSERT_NE(pos = content.find("cpu-cycles", pos), std::string::npos); |
| 366 | ASSERT_NE(pos = content.find("Samples:", pos), std::string::npos); |
| 367 | ASSERT_NE(pos = content.find("cpu-clock", pos), std::string::npos); |
| 368 | ASSERT_NE(pos = content.find("Samples:", pos), std::string::npos); |
| Yabin Cui | 2d6efe4 | 2016-04-01 20:22:35 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 371 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | b421297 | 2016-05-25 14:08:05 -0700 | [diff] [blame] | 372 | TEST_F(ReportCommandTest, report_kernel_symbol) { |
| 373 | Report(PERF_DATA_WITH_KERNEL_SYMBOL); |
| 374 | ASSERT_TRUE(success); |
| Yabin Cui | 1761a27 | 2016-06-23 17:11:14 -0700 | [diff] [blame] | 375 | ASSERT_NE(content.find("perf_event_aux"), std::string::npos); |
| Yabin Cui | b421297 | 2016-05-25 14:08:05 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 378 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 767dd17 | 2016-06-02 21:02:43 -0700 | [diff] [blame] | 379 | TEST_F(ReportCommandTest, report_dumped_symbols) { |
| 380 | Report(PERF_DATA_WITH_SYMBOLS); |
| 381 | ASSERT_TRUE(success); |
| Yabin Cui | 05ef2ea | 2016-07-11 13:50:01 -0700 | [diff] [blame] | 382 | ASSERT_NE(content.find("main"), std::string::npos); |
| Yabin Cui | c855ecc | 2016-07-11 17:04:54 -0700 | [diff] [blame] | 383 | Report(PERF_DATA_WITH_SYMBOLS_FOR_NONZERO_MINVADDR_DSO); |
| 384 | ASSERT_TRUE(success); |
| Yabin Cui | c5b4a31 | 2016-10-24 13:38:38 -0700 | [diff] [blame] | 385 | ASSERT_NE(content.find("memcpy"), std::string::npos); |
| Yabin Cui | 767dd17 | 2016-06-02 21:02:43 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 388 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | e2f1078 | 2016-12-15 12:00:44 -0800 | [diff] [blame] | 389 | TEST_F(ReportCommandTest, report_dumped_symbols_with_symfs_dir) { |
| 390 | // Check if we can report symbols when they appear both in perf.data and symfs dir. |
| 391 | Report(PERF_DATA_WITH_SYMBOLS, {"--symfs", GetTestDataDir()}); |
| 392 | ASSERT_TRUE(success); |
| 393 | ASSERT_NE(content.find("main"), std::string::npos); |
| 394 | } |
| 395 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 396 | // @CddTest = 6.1/C-0-2 |
| Wei-Ning Huang | b3f184f | 2024-03-22 00:49:18 +0800 | [diff] [blame] | 397 | TEST_F(ReportCommandTest, report_dumped_symbols_with_symdir) { |
| 398 | // Check if we can report symbols by specifying symdir. |
| 399 | Report(PERF_DATA, {"--symdir", GetTestDataDir()}, false); |
| 400 | ASSERT_TRUE(success); |
| 401 | ASSERT_NE(content.find("GlobalFunc"), std::string::npos); |
| 402 | } |
| 403 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 404 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 16f9310 | 2018-11-13 11:09:20 -0800 | [diff] [blame] | 405 | TEST_F(ReportCommandTest, report_without_symfs_dir) { |
| 406 | TemporaryFile tmpfile; |
| 407 | ASSERT_TRUE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "-o", tmpfile.path})); |
| 408 | } |
| 409 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 410 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 411 | TEST_F(ReportCommandTest, report_sort_vaddr_in_file) { |
| 412 | Report(PERF_DATA, {"--sort", "vaddr_in_file"}); |
| 413 | ASSERT_TRUE(success); |
| 414 | ASSERT_NE(content.find("VaddrInFile"), std::string::npos); |
| 415 | } |
| 416 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 417 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | eec606c | 2016-07-07 13:53:33 -0700 | [diff] [blame] | 418 | TEST_F(ReportCommandTest, check_build_id) { |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 419 | Report(PERF_DATA_FOR_BUILD_ID_CHECK, {"--symfs", GetTestData(CORRECT_SYMFS_FOR_BUILD_ID_CHECK)}); |
| Yabin Cui | eec606c | 2016-07-07 13:53:33 -0700 | [diff] [blame] | 420 | ASSERT_TRUE(success); |
| 421 | ASSERT_NE(content.find("main"), std::string::npos); |
| 422 | ASSERT_EXIT( |
| 423 | { |
| 424 | Report(PERF_DATA_FOR_BUILD_ID_CHECK, |
| 425 | {"--symfs", GetTestData(WRONG_SYMFS_FOR_BUILD_ID_CHECK)}); |
| 426 | if (!success) { |
| 427 | exit(1); |
| 428 | } |
| 429 | if (content.find("main") != std::string::npos) { |
| 430 | exit(2); |
| 431 | } |
| 432 | exit(0); |
| 433 | }, |
| Yabin Cui | 40b70ff | 2018-04-09 14:06:08 -0700 | [diff] [blame] | 434 | testing::ExitedWithCode(0), "failed to read symbols from /elf_for_build_id_check"); |
| Yabin Cui | eec606c | 2016-07-07 13:53:33 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 437 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 15475e6 | 2016-07-14 13:26:19 -0700 | [diff] [blame] | 438 | TEST_F(ReportCommandTest, no_show_ip_option) { |
| 439 | Report(PERF_DATA); |
| 440 | ASSERT_TRUE(success); |
| 441 | ASSERT_EQ(content.find("unknown"), std::string::npos); |
| 442 | Report(PERF_DATA, {"--no-show-ip"}); |
| 443 | ASSERT_TRUE(success); |
| 444 | ASSERT_NE(content.find("unknown"), std::string::npos); |
| 445 | } |
| 446 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 447 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | dec43c1 | 2016-07-29 16:40:40 -0700 | [diff] [blame] | 448 | TEST_F(ReportCommandTest, read_elf_file_warning) { |
| 449 | ASSERT_EXIT( |
| 450 | { |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 451 | Report(PERF_DATA, {"--symfs", GetTestData(SYMFS_FOR_READ_ELF_FILE_WARNING)}); |
| Yabin Cui | dec43c1 | 2016-07-29 16:40:40 -0700 | [diff] [blame] | 452 | if (!success) { |
| 453 | exit(1); |
| 454 | } |
| 455 | if (content.find("GlobalFunc") != std::string::npos) { |
| 456 | exit(2); |
| 457 | } |
| 458 | exit(0); |
| 459 | }, |
| Yabin Cui | 40b70ff | 2018-04-09 14:06:08 -0700 | [diff] [blame] | 460 | testing::ExitedWithCode(0), "failed to read symbols from /elf: File not found"); |
| Yabin Cui | dec43c1 | 2016-07-29 16:40:40 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 463 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | eafa718 | 2016-08-30 13:13:17 -0700 | [diff] [blame] | 464 | TEST_F(ReportCommandTest, report_data_generated_by_linux_perf) { |
| 465 | Report(PERF_DATA_GENERATED_BY_LINUX_PERF); |
| 466 | ASSERT_TRUE(success); |
| 467 | } |
| 468 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 469 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | c0565bb | 2016-09-29 15:59:33 -0700 | [diff] [blame] | 470 | TEST_F(ReportCommandTest, max_stack_and_percent_limit_option) { |
| 471 | Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g"}); |
| 472 | ASSERT_TRUE(success); |
| 473 | ASSERT_NE(content.find("89.03"), std::string::npos); |
| 474 | |
| 475 | Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "0"}); |
| 476 | ASSERT_TRUE(success); |
| 477 | ASSERT_EQ(content.find("89.03"), std::string::npos); |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 478 | Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "2"}); |
| Yabin Cui | c0565bb | 2016-09-29 15:59:33 -0700 | [diff] [blame] | 479 | ASSERT_TRUE(success); |
| 480 | ASSERT_NE(content.find("89.03"), std::string::npos); |
| 481 | |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 482 | Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--percent-limit", "90"}); |
| Yabin Cui | c0565bb | 2016-09-29 15:59:33 -0700 | [diff] [blame] | 483 | ASSERT_TRUE(success); |
| 484 | ASSERT_EQ(content.find("89.03"), std::string::npos); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 485 | Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--percent-limit", "70"}); |
| Yabin Cui | c0565bb | 2016-09-29 15:59:33 -0700 | [diff] [blame] | 486 | ASSERT_TRUE(success); |
| 487 | ASSERT_NE(content.find("89.03"), std::string::npos); |
| 488 | } |
| 489 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 490 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 8036c96 | 2021-08-24 10:22:50 -0700 | [diff] [blame] | 491 | TEST_F(ReportCommandTest, percent_limit_option) { |
| 492 | Report(PERF_DATA); |
| 493 | ASSERT_TRUE(success); |
| 494 | ASSERT_NE(content.find("7.70%"), std::string::npos); |
| 495 | ASSERT_NE(content.find("3.23%"), std::string::npos); |
| 496 | Report(PERF_DATA, {"--percent-limit", "3.24"}); |
| 497 | ASSERT_TRUE(success); |
| 498 | ASSERT_NE(content.find("7.70%"), std::string::npos); |
| 499 | ASSERT_EQ(content.find("3.23%"), std::string::npos); |
| 500 | } |
| 501 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 502 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 18385c4 | 2016-12-09 14:51:04 -0800 | [diff] [blame] | 503 | TEST_F(ReportCommandTest, kallsyms_option) { |
| 504 | Report(PERF_DATA, {"--kallsyms", GetTestData("kallsyms")}); |
| 505 | ASSERT_TRUE(success); |
| 506 | ASSERT_NE(content.find("FakeKernelSymbol"), std::string::npos); |
| 507 | } |
| 508 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 509 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 044861b | 2016-12-13 17:49:19 -0800 | [diff] [blame] | 510 | TEST_F(ReportCommandTest, invalid_perf_data) { |
| 511 | ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData(INVALID_PERF_DATA)})); |
| 512 | } |
| 513 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 514 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | afe99a5 | 2017-02-23 16:27:09 -0800 | [diff] [blame] | 515 | TEST_F(ReportCommandTest, raw_period_option) { |
| 516 | Report(PERF_DATA, {"--raw-period"}); |
| 517 | ASSERT_TRUE(success); |
| 518 | ASSERT_NE(content.find("GlobalFunc"), std::string::npos); |
| Chih-Hung Hsieh | f6d5b0d | 2017-08-03 14:04:06 -0700 | [diff] [blame] | 519 | ASSERT_EQ(content.find('%'), std::string::npos); |
| Yabin Cui | afe99a5 | 2017-02-23 16:27:09 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 522 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 523 | TEST_F(ReportCommandTest, full_callgraph_option) { |
| 524 | Report(CALLGRAPH_FP_PERF_DATA, {"-g"}); |
| Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 525 | ASSERT_TRUE(success); |
| 526 | ASSERT_NE(content.find("skipped in brief callgraph mode"), std::string::npos); |
| Yabin Cui | dcb2a3e | 2017-05-18 17:11:32 -0700 | [diff] [blame] | 527 | Report(CALLGRAPH_FP_PERF_DATA, {"-g", "--full-callgraph"}); |
| 528 | ASSERT_TRUE(success); |
| 529 | ASSERT_EQ(content.find("skipped in brief callgraph mode"), std::string::npos); |
| Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 532 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 68b8383 | 2017-07-19 17:54:57 -0700 | [diff] [blame] | 533 | TEST_F(ReportCommandTest, report_offcpu_time) { |
| 534 | Report(PERF_DATA_WITH_TRACE_OFFCPU, {"--children"}); |
| 535 | ASSERT_TRUE(success); |
| 536 | ASSERT_NE(content.find("Time in ns"), std::string::npos); |
| 537 | bool found = false; |
| 538 | for (auto& line : lines) { |
| 539 | if (line.find("SleepFunction") != std::string::npos) { |
| Yabin Cui | 8b5a352 | 2018-06-18 17:44:27 -0700 | [diff] [blame] | 540 | ASSERT_NE(line.find("38.76%"), std::string::npos); |
| Yabin Cui | 68b8383 | 2017-07-19 17:54:57 -0700 | [diff] [blame] | 541 | found = true; |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | ASSERT_TRUE(found); |
| 546 | } |
| 547 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 548 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 8cd9233 | 2018-03-21 14:34:29 -0700 | [diff] [blame] | 549 | TEST_F(ReportCommandTest, report_big_trace_data) { |
| 550 | Report(PERF_DATA_WITH_BIG_TRACE_DATA); |
| 551 | ASSERT_TRUE(success); |
| 552 | } |
| 553 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 554 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 30cc3c5 | 2020-05-27 13:37:18 -0700 | [diff] [blame] | 555 | TEST_F(ReportCommandTest, csv_option) { |
| 556 | Report(PERF_DATA, {"--csv"}); |
| 557 | ASSERT_TRUE(success); |
| 558 | ASSERT_NE(content.find("EventCount,EventName"), std::string::npos); |
| 559 | |
| 560 | Report(CALLGRAPH_FP_PERF_DATA, {"--children", "--csv"}); |
| 561 | ASSERT_TRUE(success); |
| 562 | ASSERT_NE(content.find("AccEventCount,SelfEventCount,EventName"), std::string::npos); |
| 563 | } |
| 564 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 565 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 51dca6f | 2021-12-16 19:00:41 -0800 | [diff] [blame] | 566 | TEST_F(ReportCommandTest, csv_separator_option) { |
| 567 | Report(PERF_DATA, {"--csv", "--csv-separator", ";"}); |
| 568 | ASSERT_TRUE(success); |
| 569 | ASSERT_NE(content.find("EventCount;EventName"), std::string::npos); |
| 570 | ASSERT_NE(content.find(";cpu-cycles"), std::string::npos); |
| 571 | } |
| 572 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 573 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 075dd18 | 2020-08-05 19:51:36 +0000 | [diff] [blame] | 574 | TEST_F(ReportCommandTest, dso_path_for_jit_cache) { |
| 575 | Report("perf_with_jit_symbol.data", {"--sort", "dso"}); |
| 576 | ASSERT_TRUE(success); |
| 577 | ASSERT_NE(content.find("[JIT app cache]"), std::string::npos); |
| 578 | |
| 579 | // Check if we can filter dso by "[JIT app cache]". |
| 580 | Report("perf_with_jit_symbol.data", {"--dsos", "[JIT app cache]"}); |
| 581 | ASSERT_TRUE(success); |
| 582 | ASSERT_NE(content.find("[JIT app cache]"), std::string::npos); |
| 583 | } |
| 584 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 585 | // @CddTest = 6.1/C-0-2 |
| Evgeny Eltsin | 3775b14 | 2020-08-28 13:00:04 +0200 | [diff] [blame] | 586 | TEST_F(ReportCommandTest, generic_jit_symbols) { |
| 587 | Report("perf_with_generic_git_symbols.data", {"--sort", "symbol"}); |
| 588 | ASSERT_TRUE(success); |
| 589 | ASSERT_NE(std::string::npos, content.find("generic_jit_symbol_one")); |
| 590 | } |
| 591 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 592 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | e3ca998 | 2020-10-16 13:16:26 -0700 | [diff] [blame] | 593 | TEST_F(ReportCommandTest, cpu_option) { |
| 594 | Report("perf.data"); |
| 595 | ASSERT_TRUE(success); |
| 596 | ASSERT_EQ(2409, GetSampleCount()); |
| 597 | Report("perf.data", {"--cpu", "2"}); |
| 598 | ASSERT_TRUE(success); |
| 599 | ASSERT_EQ(603, GetSampleCount()); |
| 600 | Report("perf.data", {"--cpu", "2-6,16"}); |
| 601 | ASSERT_TRUE(success); |
| 602 | ASSERT_EQ(1806, GetSampleCount()); |
| 603 | Report("perf.data", {"--cpu", "2-6", "--cpu", "16"}); |
| 604 | ASSERT_TRUE(success); |
| 605 | ASSERT_EQ(1806, GetSampleCount()); |
| 606 | ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData("perf.data"), "--cpu", "-2"})); |
| 607 | } |
| 608 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 609 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 610 | TEST_F(ReportCommandTest, print_event_count_option) { |
| 611 | // Report record file not recorded with --add-counter. |
| 612 | Report("perf.data", {"--print-event-count"}); |
| 613 | ASSERT_TRUE(success); |
| 614 | ASSERT_NE(content.find("EventCount"), std::string::npos); |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 615 | ASSERT_TRUE( |
| 616 | RegEx::Create(R"(325005586\s+elf\s+26083\s+26083\s+/elf\s+GlobalFunc)")->Search(content)); |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 617 | |
| 618 | // Report record file recorded with --add-counter. |
| 619 | const std::string record_file = "perf_with_add_counter.data"; |
| 620 | Report(record_file, {"--print-event-count"}); |
| 621 | ASSERT_TRUE(success); |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 622 | ASSERT_TRUE(RegEx::Create(R"(EventCount_cpu-cycles\s+EventCount_instructions)")->Search(content)); |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 623 | ASSERT_TRUE( |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 624 | RegEx::Create(R"(175099\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)")->Search(content)); |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 625 | |
| 626 | // Report accumulated event counts. |
| 627 | Report(record_file, {"--print-event-count", "--children"}); |
| 628 | ASSERT_TRUE(success); |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 629 | ASSERT_TRUE( |
| 630 | RegEx::Create( |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 631 | R"(AccEventCount_cpu-cycles\s+SelfEventCount_cpu-cycles\s+AccEventCount_instructions\s+)" |
| Yabin Cui | f00f4fc | 2022-11-23 15:15:30 -0800 | [diff] [blame] | 632 | R"(SelfEventCount_instructions)") |
| 633 | ->Search(content)); |
| 634 | ASSERT_TRUE( |
| 635 | RegEx::Create(R"(175099\s+175099\s+140443\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)") |
| 636 | ->Search(content)); |
| 637 | ASSERT_TRUE( |
| 638 | RegEx::Create(R"(366116\s+0\s+297474\s+0\s+sleep\s+689664\s+689664.+__libc_start_main)") |
| 639 | ->Search(content)); |
| Yabin Cui | 32b9627 | 2021-12-22 11:45:30 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 642 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 5ea3bc1 | 2022-01-05 11:50:00 -0800 | [diff] [blame] | 643 | TEST_F(ReportCommandTest, exclude_include_pid_options) { |
| 644 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--exclude-pid", "17441"}); |
| 645 | ASSERT_TRUE(success); |
| 646 | ASSERT_TRUE(AllItemsWithString(lines, {"17443", "17444"})); |
| 647 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--include-pid", "17441"}); |
| 648 | ASSERT_TRUE(success); |
| 649 | ASSERT_TRUE(AllItemsWithString(lines, {"17441"})); |
| 650 | } |
| 651 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 652 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 5ea3bc1 | 2022-01-05 11:50:00 -0800 | [diff] [blame] | 653 | TEST_F(ReportCommandTest, exclude_include_tid_options) { |
| 654 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, |
| 655 | {"--sort", "tid", "--exclude-tid", "17441,17443,17444"}); |
| 656 | ASSERT_TRUE(success); |
| 657 | ASSERT_TRUE(AllItemsWithString(lines, {"17445", "17446", "17447"})); |
| 658 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, |
| 659 | {"--sort", "tid", "--include-tid", "17441,17443,17444"}); |
| 660 | ASSERT_TRUE(success); |
| 661 | ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17443", "17444"})); |
| 662 | } |
| 663 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 664 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 5ea3bc1 | 2022-01-05 11:50:00 -0800 | [diff] [blame] | 665 | TEST_F(ReportCommandTest, exclude_include_process_name_options) { |
| 666 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--exclude-process-name", "t1"}); |
| 667 | ASSERT_TRUE(success); |
| 668 | ASSERT_TRUE(AllItemsWithString(lines, {"simpleperf"})); |
| 669 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--include-process-name", "t1"}); |
| 670 | ASSERT_TRUE(success); |
| 671 | ASSERT_TRUE(AllItemsWithString(lines, {"t1"})); |
| 672 | } |
| 673 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 674 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 5ea3bc1 | 2022-01-05 11:50:00 -0800 | [diff] [blame] | 675 | TEST_F(ReportCommandTest, exclude_include_thread_name_options) { |
| 676 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--exclude-thread-name", "t1"}); |
| 677 | ASSERT_TRUE(success); |
| 678 | ASSERT_TRUE(AllItemsWithString(lines, {"simpleperf"})); |
| 679 | Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--include-thread-name", "t1"}); |
| 680 | ASSERT_TRUE(success); |
| 681 | ASSERT_TRUE(AllItemsWithString(lines, {"t1"})); |
| 682 | } |
| 683 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 684 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | c4d9ead | 2022-01-06 15:41:31 -0800 | [diff] [blame] | 685 | TEST_F(ReportCommandTest, filter_file_option) { |
| 686 | std::string filter_data = |
| 687 | "GLOBAL_BEGIN 684943449406175\n" |
| 688 | "GLOBAL_END 684943449406176"; |
| 689 | TemporaryFile tmpfile; |
| 690 | ASSERT_TRUE(android::base::WriteStringToFd(filter_data, tmpfile.fd)); |
| 691 | Report("perf_display_bitmaps.data", {"--filter-file", tmpfile.path}); |
| 692 | ASSERT_TRUE(success); |
| 693 | ASSERT_EQ(GetSampleCount(), 1); |
| 694 | |
| 695 | // PERF_DATA uses clock perf, which doesn't match the default clock in filter data. |
| 696 | CapturedStderr capture; |
| 697 | ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "--filter-file", tmpfile.path})); |
| 698 | capture.Stop(); |
| 699 | ASSERT_NE(capture.str().find("doesn't match clock used in time filter"), std::string::npos); |
| 700 | } |
| 701 | |
| Yabin Cui | 19e6b6d | 2016-03-10 11:49:57 -0800 | [diff] [blame] | 702 | #if defined(__linux__) |
| Yabin Cui | 003b245 | 2016-09-29 15:32:45 -0700 | [diff] [blame] | 703 | #include "event_selection_set.h" |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 704 | |
| 705 | static std::unique_ptr<Command> RecordCmd() { |
| 706 | return CreateCommandInstance("record"); |
| Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 707 | } |
| Yabin Cui | b1a885b | 2016-02-14 19:18:02 -0800 | [diff] [blame] | 708 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 709 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 710 | TEST_F(ReportCommandTest, dwarf_callgraph) { |
| Yabin Cui | 8faa615 | 2018-06-07 15:52:57 -0700 | [diff] [blame] | 711 | TEST_REQUIRE_HW_COUNTER(); |
| Yabin Cui | 64a9ecd | 2017-09-13 13:21:32 -0700 | [diff] [blame] | 712 | OMIT_TEST_ON_NON_NATIVE_ABIS(); |
| Yabin Cui | d18c42e | 2017-07-12 14:50:07 -0700 | [diff] [blame] | 713 | ASSERT_TRUE(IsDwarfCallChainSamplingSupported()); |
| 714 | std::vector<std::unique_ptr<Workload>> workloads; |
| 715 | CreateProcesses(1, &workloads); |
| 716 | std::string pid = std::to_string(workloads[0]->GetPid()); |
| 717 | TemporaryFile tmp_file; |
| Yabin Cui | 2412efb | 2025-01-24 14:40:42 -0800 | [diff] [blame] | 718 | ASSERT_TRUE(RecordCmd()->Run( |
| 719 | {"-p", pid, "-g", "-o", tmp_file.path, "-e", "cpu-cycles:u", "sleep", SLEEP_SEC})); |
| Yabin Cui | d18c42e | 2017-07-12 14:50:07 -0700 | [diff] [blame] | 720 | ReportRaw(tmp_file.path, {"-g"}); |
| 721 | ASSERT_TRUE(success); |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 724 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | 8f680f6 | 2016-03-18 18:47:43 -0700 | [diff] [blame] | 725 | TEST_F(ReportCommandTest, report_dwarf_callgraph_of_nativelib_in_apk) { |
| Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 726 | Report(NATIVELIB_IN_APK_PERF_DATA, {"-g"}); |
| Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 727 | ASSERT_NE(content.find(GetUrlInApk(APK_FILE, NATIVELIB_IN_APK)), std::string::npos); |
| Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 728 | ASSERT_NE(content.find("Func2"), std::string::npos); |
| 729 | ASSERT_NE(content.find("Func1"), std::string::npos); |
| 730 | ASSERT_NE(content.find("GlobalFunc"), std::string::npos); |
| Yabin Cui | 8f680f6 | 2016-03-18 18:47:43 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 733 | // @CddTest = 6.1/C-0-2 |
| Yabin Cui | d3cb3b0 | 2017-07-24 14:59:46 -0700 | [diff] [blame] | 734 | TEST_F(ReportCommandTest, exclude_kernel_callchain) { |
| Yabin Cui | 2412efb | 2025-01-24 14:40:42 -0800 | [diff] [blame] | 735 | TEST_REQUIRE_KERNEL_EVENTS(); |
| Yabin Cui | 8faa615 | 2018-06-07 15:52:57 -0700 | [diff] [blame] | 736 | TEST_REQUIRE_HW_COUNTER(); |
| Yabin Cui | d3cb3b0 | 2017-07-24 14:59:46 -0700 | [diff] [blame] | 737 | TEST_REQUIRE_HOST_ROOT(); |
| Yabin Cui | 64a9ecd | 2017-09-13 13:21:32 -0700 | [diff] [blame] | 738 | OMIT_TEST_ON_NON_NATIVE_ABIS(); |
| Yabin Cui | d3cb3b0 | 2017-07-24 14:59:46 -0700 | [diff] [blame] | 739 | std::vector<std::unique_ptr<Workload>> workloads; |
| 740 | CreateProcesses(1, &workloads); |
| 741 | std::string pid = std::to_string(workloads[0]->GetPid()); |
| 742 | TemporaryFile tmpfile; |
| Yabin Cui | d180e31 | 2021-11-17 16:54:01 -0800 | [diff] [blame] | 743 | ASSERT_TRUE(RecordCmd()->Run({"--trace-offcpu", "-e", "cpu-clock:u", "-p", pid, "--duration", "2", |
| 744 | "-o", tmpfile.path, "-g"})); |
| Yabin Cui | d3cb3b0 | 2017-07-24 14:59:46 -0700 | [diff] [blame] | 745 | ReportRaw(tmpfile.path, {"-g"}); |
| 746 | ASSERT_TRUE(success); |
| 747 | ASSERT_EQ(content.find("[kernel.kallsyms]"), std::string::npos); |
| 748 | } |
| 749 | |
| Yabin Cui | 6e51bef | 2016-02-23 21:41:03 -0800 | [diff] [blame] | 750 | #endif |