2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
23 #include <sys/types.h>
27 #include <android-base/stringprintf.h>
28 #include <cutils/properties.h>
30 #include "perfprofdcore.h"
31 #include "configreader.h"
32 #include "perfprofdutils.h"
33 #include "perfprofdmockutils.h"
35 #include "perf_profile.pb.h"
36 #include "google/protobuf/text_format.h"
39 // Set to argv[0] on startup
41 static const char *executable_path;
44 // test_dir is the directory containing the test executable and
45 // any files associated with the test (will be created by the harness).
47 // dest_dir is a subdirectory of test_dir that we'll create on the fly
48 // at the start of each testpoint (into which new files can be written),
49 // then delete at end of testpoint.
51 static std::string test_dir;
52 static std::string dest_dir;
54 // Path to perf executable on device
55 #define PERFPATH "/system/bin/perf"
57 // Temporary config file that we will emit for the daemon to read
58 #define CONFIGFILE "perfprofd.conf"
60 static std::string encoded_file_path(int seq)
62 return android::base::StringPrintf("%s/perf.data.encoded.%d",
63 dest_dir.c_str(), seq);
66 class PerfProfdTest : public testing::Test {
68 virtual void SetUp() {
69 mock_perfprofdutils_init();
74 virtual void TearDown() {
75 mock_perfprofdutils_finish();
88 void create_dest_dir() {
90 ASSERT_FALSE(dest_dir == "");
92 std::string cmd("rm -rf ");
96 std::string cmd("mkdir -p ");
103 if (test_dir == "") {
104 ASSERT_TRUE(executable_path != nullptr);
105 std::string s(executable_path);
106 auto found = s.find_last_of('/');
107 test_dir = s.substr(0,found);
115 static bool bothWhiteSpace(char lhs, char rhs)
117 return (std::isspace(lhs) && std::isspace(rhs));
121 // Squeeze out repeated whitespace from expected/actual logs.
123 static std::string squeezeWhite(const std::string &str,
127 if (dump) { fprintf(stderr, "raw %s is %s\n", tag, str.c_str()); }
128 std::string result(str);
129 std::replace( result.begin(), result.end(), '\n', ' ');
130 auto new_end = std::unique(result.begin(), result.end(), bothWhiteSpace);
131 result.erase(new_end, result.end());
132 while (result.begin() != result.end() && std::isspace(*result.rbegin())) {
135 if (dump) { fprintf(stderr, "squeezed %s is %s\n", tag, result.c_str()); }
140 /// Helper class to kick off a run of the perfprofd daemon with a specific
143 class PerfProfdRunner {
146 : config_path_(test_dir)
148 config_path_ += "/" CONFIGFILE;
153 remove_processed_file();
156 void addToConfig(const std::string &line)
158 config_text_ += line;
159 config_text_ += "\n";
162 void remove_semaphore_file()
164 std::string semaphore(test_dir);
165 semaphore += "/" SEMAPHORE_FILENAME;
166 unlink(semaphore.c_str());
169 void create_semaphore_file()
171 std::string semaphore(test_dir);
172 semaphore += "/" SEMAPHORE_FILENAME;
173 close(open(semaphore.c_str(), O_WRONLY|O_CREAT));
176 void write_processed_file(int start_seq, int end_seq)
178 std::string processed = test_dir + "/" PROCESSED_FILENAME;
179 FILE *fp = fopen(processed.c_str(), "w");
180 for (int i = start_seq; i < end_seq; i++) {
181 fprintf(fp, "%d\n", i);
186 void remove_processed_file()
188 std::string processed = test_dir + "/" PROCESSED_FILENAME;
189 unlink(processed.c_str());
194 static const char *argv[3] = { "perfprofd", "-c", "" };
195 argv[2] = config_path_.c_str();
197 writeConfigFile(config_path_, config_text_);
199 // execute daemon main
200 return perfprofd_main(3, (char **) argv);
204 std::string config_path_;
205 std::string config_text_;
207 void writeConfigFile(const std::string &config_path,
208 const std::string &config_text)
210 FILE *fp = fopen(config_path.c_str(), "w");
211 ASSERT_TRUE(fp != nullptr);
212 fprintf(fp, "%s\n", config_text.c_str());
217 //......................................................................
219 static void readEncodedProfile(const char *testpoint,
220 wireless_android_play_playlog::AndroidPerfProfile &encodedProfile)
223 int perf_data_stat_result = stat(encoded_file_path(0).c_str(), &statb);
224 ASSERT_NE(-1, perf_data_stat_result);
228 encoded.resize(statb.st_size);
229 FILE *ifp = fopen(encoded_file_path(0).c_str(), "r");
230 ASSERT_NE(nullptr, ifp);
231 size_t items_read = fread((void*) encoded.data(), statb.st_size, 1, ifp);
232 ASSERT_EQ(1, items_read);
236 encodedProfile.ParseFromString(encoded);
239 static std::string encodedLoadModuleToString(const wireless_android_play_playlog::LoadModule &lm)
241 std::stringstream ss;
242 ss << "name: \"" << lm.name() << "\"\n";
243 if (lm.build_id() != "") {
244 ss << "build_id: \"" << lm.build_id() << "\"\n";
249 static std::string encodedModuleSamplesToString(const wireless_android_play_playlog::LoadModuleSamples &mod)
251 std::stringstream ss;
253 ss << "load_module_id: " << mod.load_module_id() << "\n";
254 for (size_t k = 0; k < mod.address_samples_size(); k++) {
255 const auto &sample = mod.address_samples(k);
256 ss << " address_samples {\n";
257 for (size_t l = 0; l < mod.address_samples(k).address_size();
259 auto address = mod.address_samples(k).address(l);
260 ss << " address: " << address << "\n";
262 ss << " count: " << sample.count() << "\n";
268 #define RAW_RESULT(x) #x
271 // Check to see if the log messages emitted by the daemon
272 // match the expected result. By default we use a partial
273 // match, e.g. if we see the expected excerpt anywhere in the
274 // result, it's a match (for exact match, set exact to true)
276 static void compareLogMessages(const std::string &actual,
277 const std::string &expected,
278 const char *testpoint,
279 bool exactMatch=false)
281 std::string sqexp = squeezeWhite(expected, "expected");
282 std::string sqact = squeezeWhite(actual, "actual");
284 EXPECT_STREQ(sqexp.c_str(), sqact.c_str());
286 std::size_t foundpos = sqact.find(sqexp);
287 bool wasFound = true;
288 if (foundpos == std::string::npos) {
289 std::cerr << testpoint << ": expected result not found\n";
290 std::cerr << " Actual: \"" << sqact << "\"\n";
291 std::cerr << " Expected: \"" << sqexp << "\"\n";
294 EXPECT_TRUE(wasFound);
298 TEST_F(PerfProfdTest, MissingGMS)
301 // AWP requires cooperation between the daemon and the GMS core
302 // piece. If we're running on a device that has an old or damaged
303 // version of GMS core, then the config directory we're interested in
304 // may not be there. This test insures that the daemon does the
305 // right thing in this case.
307 PerfProfdRunner runner;
308 runner.addToConfig("only_debug_build=0");
309 runner.addToConfig("trace_config_read=0");
310 runner.addToConfig("config_directory=/does/not/exist");
311 runner.addToConfig("main_loop_iterations=1");
312 runner.addToConfig("use_fixed_seed=1");
313 runner.addToConfig("collection_interval=100");
316 int daemon_main_return_code = runner.invoke();
318 // Check return code from daemon
319 EXPECT_EQ(0, daemon_main_return_code);
321 // Verify log contents
322 const std::string expected = RAW_RESULT(
324 W: unable to open config directory /does/not/exist: (No such file or directory)
325 I: profile collection skipped (missing config directory)
328 // check to make sure entire log matches
329 compareLogMessages(mock_perfprofdutils_getlogged(),
330 expected, "MissingGMS");
334 TEST_F(PerfProfdTest, MissingOptInSemaphoreFile)
337 // Android device owners must opt in to "collect and report usage
338 // data" in order for us to be able to collect profiles. The opt-in
339 // check is performed in the GMS core component; if the check
340 // passes, then it creates a semaphore file for the daemon to pick
343 PerfProfdRunner runner;
344 runner.addToConfig("only_debug_build=0");
345 std::string cfparam("config_directory="); cfparam += test_dir;
346 runner.addToConfig(cfparam);
347 std::string ddparam("destination_directory="); ddparam += dest_dir;
348 runner.addToConfig(ddparam);
349 runner.addToConfig("main_loop_iterations=1");
350 runner.addToConfig("use_fixed_seed=1");
351 runner.addToConfig("collection_interval=100");
353 runner.remove_semaphore_file();
356 int daemon_main_return_code = runner.invoke();
358 // Check return code from daemon
359 EXPECT_EQ(0, daemon_main_return_code);
361 // Verify log contents
362 const std::string expected = RAW_RESULT(
363 I: profile collection skipped (missing semaphore file)
365 // check to make sure log excerpt matches
366 compareLogMessages(mock_perfprofdutils_getlogged(),
367 expected, "MissingOptInSemaphoreFile");
370 TEST_F(PerfProfdTest, MissingPerfExecutable)
373 // Perfprofd uses the 'simpleperf' tool to collect profiles
374 // (although this may conceivably change in the future). This test
375 // checks to make sure that if 'simpleperf' is not present we bail out
376 // from collecting profiles.
378 PerfProfdRunner runner;
379 runner.addToConfig("only_debug_build=0");
380 runner.addToConfig("trace_config_read=1");
381 std::string cfparam("config_directory="); cfparam += test_dir;
382 runner.addToConfig(cfparam);
383 std::string ddparam("destination_directory="); ddparam += dest_dir;
384 runner.addToConfig(ddparam);
385 runner.addToConfig("main_loop_iterations=1");
386 runner.addToConfig("use_fixed_seed=1");
387 runner.addToConfig("collection_interval=100");
388 runner.addToConfig("perf_path=/does/not/exist");
390 // Create semaphore file
391 runner.create_semaphore_file();
394 int daemon_main_return_code = runner.invoke();
396 // Check return code from daemon
397 EXPECT_EQ(0, daemon_main_return_code);
399 // expected log contents
400 const std::string expected = RAW_RESULT(
401 I: profile collection skipped (missing 'perf' executable)
403 // check to make sure log excerpt matches
404 compareLogMessages(mock_perfprofdutils_getlogged(),
405 expected, "MissingPerfExecutable");
408 TEST_F(PerfProfdTest, BadPerfRun)
411 // Perf tools tend to be tightly coupled with a specific kernel
412 // version -- if things are out of sync perf could fail or
413 // crash. This test makes sure that we detect such a case and log
416 PerfProfdRunner runner;
417 runner.addToConfig("only_debug_build=0");
418 std::string cfparam("config_directory="); cfparam += test_dir;
419 runner.addToConfig(cfparam);
420 std::string ddparam("destination_directory="); ddparam += dest_dir;
421 runner.addToConfig(ddparam);
422 runner.addToConfig("main_loop_iterations=1");
423 runner.addToConfig("use_fixed_seed=1");
424 runner.addToConfig("collection_interval=100");
425 runner.addToConfig("perf_path=/system/bin/false");
427 // Create semaphore file
428 runner.create_semaphore_file();
431 int daemon_main_return_code = runner.invoke();
433 // Check return code from daemon
434 EXPECT_EQ(0, daemon_main_return_code);
436 // Verify log contents
437 const std::string expected = RAW_RESULT(
438 I: profile collection failed (perf record returned bad exit status)
441 // check to make sure log excerpt matches
442 compareLogMessages(mock_perfprofdutils_getlogged(),
443 expected, "BadPerfRun");
446 TEST_F(PerfProfdTest, ConfigFileParsing)
449 // Gracefully handly malformed items in the config file
451 PerfProfdRunner runner;
452 runner.addToConfig("only_debug_build=0");
453 runner.addToConfig("main_loop_iterations=1");
454 runner.addToConfig("collection_interval=100");
455 runner.addToConfig("use_fixed_seed=1");
456 runner.addToConfig("destination_directory=/does/not/exist");
458 // assorted bad syntax
459 runner.addToConfig("collection_interval=0");
460 runner.addToConfig("collection_interval=-1");
461 runner.addToConfig("collection_interval=2");
462 runner.addToConfig("nonexistent_key=something");
463 runner.addToConfig("no_equals_stmt");
466 int daemon_main_return_code = runner.invoke();
468 // Check return code from daemon
469 EXPECT_EQ(0, daemon_main_return_code);
471 // Verify log contents
472 const std::string expected = RAW_RESULT(
473 W: line 6: specified value 0 for 'collection_interval' outside permitted range [100 4294967295] (ignored)
474 W: line 7: malformed unsigned value (ignored)
475 W: line 8: specified value 2 for 'collection_interval' outside permitted range [100 4294967295] (ignored)
476 W: line 9: unknown option 'nonexistent_key' ignored
477 W: line 10: line malformed (no '=' found)
480 // check to make sure log excerpt matches
481 compareLogMessages(mock_perfprofdutils_getlogged(),
482 expected, "ConfigFileParsing");
485 TEST_F(PerfProfdTest, ProfileCollectionAnnotations)
487 unsigned util1 = collect_cpu_utilization();
488 EXPECT_LE(util1, 100);
491 // NB: expectation is that when we run this test, the device will be
492 // completed booted, will be on charger, and will not have the camera
494 EXPECT_FALSE(get_booting());
495 EXPECT_TRUE(get_charging());
496 EXPECT_FALSE(get_camera_active());
499 TEST_F(PerfProfdTest, BasicRunWithCannedPerf)
502 // Verify the portion of the daemon that reads and encodes
503 // perf.data files. Here we run the encoder on a canned perf.data
504 // file and verify that the resulting protobuf contains what
505 // we think it should contain.
507 std::string input_perf_data(test_dir);
508 input_perf_data += "/canned.perf.data";
510 // Set up config to avoid these annotations (they are tested elsewhere)
512 config.overrideUnsignedEntry("collect_cpu_utilization", 0);
513 config.overrideUnsignedEntry("collect_charging_state", 0);
514 config.overrideUnsignedEntry("collect_camera_active", 0);
516 // Kick off encoder and check return code
517 PROFILE_RESULT result =
518 encode_to_proto(input_perf_data, encoded_file_path(0).c_str(), config, 0);
519 EXPECT_EQ(OK_PROFILE_COLLECTION, result);
521 // Read and decode the resulting perf.data.encoded file
522 wireless_android_play_playlog::AndroidPerfProfile encodedProfile;
523 readEncodedProfile("BasicRunWithCannedPerf",
526 // Expect 29 load modules
527 EXPECT_EQ(29, encodedProfile.programs_size());
529 // Check a couple of load modules
530 { const auto &lm0 = encodedProfile.load_modules(0);
531 std::string act_lm0 = encodedLoadModuleToString(lm0);
532 std::string sqact0 = squeezeWhite(act_lm0, "actual for lm 0");
533 const std::string expected_lm0 = RAW_RESULT(
534 name: "/data/app/com.google.android.apps.plus-1/lib/arm/libcronet.so"
536 std::string sqexp0 = squeezeWhite(expected_lm0, "expected_lm0");
537 EXPECT_STREQ(sqexp0.c_str(), sqact0.c_str());
539 { const auto &lm9 = encodedProfile.load_modules(9);
540 std::string act_lm9 = encodedLoadModuleToString(lm9);
541 std::string sqact9 = squeezeWhite(act_lm9, "actual for lm 9");
542 const std::string expected_lm9 = RAW_RESULT(
543 name: "/system/lib/libandroid_runtime.so" build_id: "8164ed7b3a8b8f5a220d027788922510"
545 std::string sqexp9 = squeezeWhite(expected_lm9, "expected_lm9");
546 EXPECT_STREQ(sqexp9.c_str(), sqact9.c_str());
549 // Examine some of the samples now
550 { const auto &p1 = encodedProfile.programs(0);
551 const auto &lm1 = p1.modules(0);
552 std::string act_lm1 = encodedModuleSamplesToString(lm1);
553 std::string sqact1 = squeezeWhite(act_lm1, "actual for lm1");
554 const std::string expected_lm1 = RAW_RESULT(
555 load_module_id: 9 address_samples { address: 296100 count: 1 }
557 std::string sqexp1 = squeezeWhite(expected_lm1, "expected_lm1");
558 EXPECT_STREQ(sqexp1.c_str(), sqact1.c_str());
560 { const auto &p1 = encodedProfile.programs(2);
561 const auto &lm2 = p1.modules(0);
562 std::string act_lm2 = encodedModuleSamplesToString(lm2);
563 std::string sqact2 = squeezeWhite(act_lm2, "actual for lm2");
564 const std::string expected_lm2 = RAW_RESULT(
566 address_samples { address: 28030244 count: 1 }
567 address_samples { address: 29657840 count: 1 }
569 std::string sqexp2 = squeezeWhite(expected_lm2, "expected_lm2");
570 EXPECT_STREQ(sqexp2.c_str(), sqact2.c_str());
574 TEST_F(PerfProfdTest, CallchainRunWithCannedPerf)
576 // This test makes sure that the perf.data converter
577 // can handle call chains.
579 std::string input_perf_data(test_dir);
580 input_perf_data += "/callchain.canned.perf.data";
582 // Set up config to avoid these annotations (they are tested elsewhere)
584 config.overrideUnsignedEntry("collect_cpu_utilization", 0);
585 config.overrideUnsignedEntry("collect_charging_state", 0);
586 config.overrideUnsignedEntry("collect_camera_active", 0);
588 // Kick off encoder and check return code
589 PROFILE_RESULT result =
590 encode_to_proto(input_perf_data, encoded_file_path(0).c_str(), config, 0);
591 EXPECT_EQ(OK_PROFILE_COLLECTION, result);
593 // Read and decode the resulting perf.data.encoded file
594 wireless_android_play_playlog::AndroidPerfProfile encodedProfile;
595 readEncodedProfile("BasicRunWithCannedPerf",
599 // Expect 4 programs 8 load modules
600 EXPECT_EQ(4, encodedProfile.programs_size());
601 EXPECT_EQ(8, encodedProfile.load_modules_size());
603 // Check a couple of load modules
604 { const auto &lm0 = encodedProfile.load_modules(0);
605 std::string act_lm0 = encodedLoadModuleToString(lm0);
606 std::string sqact0 = squeezeWhite(act_lm0, "actual for lm 0");
607 const std::string expected_lm0 = RAW_RESULT(
608 name: "/system/bin/dex2oat"
609 build_id: "ee12bd1a1de39422d848f249add0afc4"
611 std::string sqexp0 = squeezeWhite(expected_lm0, "expected_lm0");
612 EXPECT_STREQ(sqexp0.c_str(), sqact0.c_str());
614 { const auto &lm1 = encodedProfile.load_modules(1);
615 std::string act_lm1 = encodedLoadModuleToString(lm1);
616 std::string sqact1 = squeezeWhite(act_lm1, "actual for lm 1");
617 const std::string expected_lm1 = RAW_RESULT(
618 name: "/system/bin/linker"
619 build_id: "a36715f673a4a0aa76ef290124c516cc"
621 std::string sqexp1 = squeezeWhite(expected_lm1, "expected_lm1");
622 EXPECT_STREQ(sqexp1.c_str(), sqact1.c_str());
625 // Examine some of the samples now
626 { const auto &p0 = encodedProfile.programs(0);
627 const auto &lm1 = p0.modules(0);
628 std::string act_lm1 = encodedModuleSamplesToString(lm1);
629 std::string sqact1 = squeezeWhite(act_lm1, "actual for lm1");
630 const std::string expected_lm1 = RAW_RESULT(
632 address_samples { address: 108552 count: 2 }
634 std::string sqexp1 = squeezeWhite(expected_lm1, "expected_lm1");
635 EXPECT_STREQ(sqexp1.c_str(), sqact1.c_str());
637 { const auto &p4 = encodedProfile.programs(3);
638 const auto &lm2 = p4.modules(1);
639 std::string act_lm2 = encodedModuleSamplesToString(lm2);
640 std::string sqact2 = squeezeWhite(act_lm2, "actual for lm2");
641 const std::string expected_lm2 = RAW_RESULT(
642 load_module_id: 2 address_samples { address: 403913 count: 1 } address_samples { address: 840761 count: 1 } address_samples { address: 846481 count: 1 } address_samples { address: 999053 count: 1 } address_samples { address: 1012959 count: 1 } address_samples { address: 1524309 count: 1 } address_samples { address: 1580779 count: 1 } address_samples { address: 4287986288 count: 1 }
644 std::string sqexp2 = squeezeWhite(expected_lm2, "expected_lm2");
645 EXPECT_STREQ(sqexp2.c_str(), sqact2.c_str());
649 TEST_F(PerfProfdTest, BasicRunWithLivePerf)
652 // Basic test to exercise the main loop of the daemon. It includes
655 PerfProfdRunner runner;
656 runner.addToConfig("only_debug_build=0");
657 std::string ddparam("destination_directory="); ddparam += dest_dir;
658 runner.addToConfig(ddparam);
659 std::string cfparam("config_directory="); cfparam += test_dir;
660 runner.addToConfig(cfparam);
661 runner.addToConfig("main_loop_iterations=1");
662 runner.addToConfig("use_fixed_seed=12345678");
663 runner.addToConfig("max_unprocessed_profiles=100");
664 runner.addToConfig("collection_interval=9999");
665 runner.addToConfig("sample_duration=2");
667 // Create semaphore file
668 runner.create_semaphore_file();
671 int daemon_main_return_code = runner.invoke();
673 // Check return code from daemon
674 EXPECT_EQ(0, daemon_main_return_code);
676 // Read and decode the resulting perf.data.encoded file
677 wireless_android_play_playlog::AndroidPerfProfile encodedProfile;
678 readEncodedProfile("BasicRunWithLivePerf", encodedProfile);
680 // Examine what we get back. Since it's a live profile, we can't
681 // really do much in terms of verifying the contents.
682 EXPECT_LT(0, encodedProfile.programs_size());
684 // Verify log contents
685 const std::string expected = RAW_RESULT(
686 I: starting Android Wide Profiling daemon
687 I: config file path set to /data/nativetest/perfprofd_test/perfprofd.conf
688 I: random seed set to 12345678
690 I: initiating profile collection
691 I: profile collection complete
692 I: sleep 9325 seconds
693 I: finishing Android Wide Profiling daemon
695 // check to make sure log excerpt matches
696 compareLogMessages(mock_perfprofdutils_getlogged(),
697 expected, "BasicRunWithLivePerf", true);
700 TEST_F(PerfProfdTest, MultipleRunWithLivePerf)
703 // Basic test to exercise the main loop of the daemon. It includes
706 PerfProfdRunner runner;
707 runner.addToConfig("only_debug_build=0");
708 std::string ddparam("destination_directory="); ddparam += dest_dir;
709 runner.addToConfig(ddparam);
710 std::string cfparam("config_directory="); cfparam += test_dir;
711 runner.addToConfig(cfparam);
712 runner.addToConfig("main_loop_iterations=3");
713 runner.addToConfig("use_fixed_seed=12345678");
714 runner.addToConfig("collection_interval=9999");
715 runner.addToConfig("sample_duration=2");
716 runner.write_processed_file(1, 2);
718 // Create semaphore file
719 runner.create_semaphore_file();
722 int daemon_main_return_code = runner.invoke();
724 // Check return code from daemon
725 EXPECT_EQ(0, daemon_main_return_code);
727 // Read and decode the resulting perf.data.encoded file
728 wireless_android_play_playlog::AndroidPerfProfile encodedProfile;
729 readEncodedProfile("BasicRunWithLivePerf", encodedProfile);
731 // Examine what we get back. Since it's a live profile, we can't
732 // really do much in terms of verifying the contents.
733 EXPECT_LT(0, encodedProfile.programs_size());
735 // Examine that encoded.1 file is removed while encoded.{0|2} exists.
736 EXPECT_EQ(0, access(encoded_file_path(0).c_str(), F_OK));
737 EXPECT_NE(0, access(encoded_file_path(1).c_str(), F_OK));
738 EXPECT_EQ(0, access(encoded_file_path(2).c_str(), F_OK));
740 // Verify log contents
741 const std::string expected = RAW_RESULT(
742 I: starting Android Wide Profiling daemon
743 I: config file path set to /data/nativetest/perfprofd_test/perfprofd.conf
744 I: random seed set to 12345678
746 I: initiating profile collection
747 I: profile collection complete
748 I: sleep 9325 seconds
749 I: sleep 4974 seconds
750 I: initiating profile collection
751 I: profile collection complete
752 I: sleep 5025 seconds
754 I: initiating profile collection
755 I: profile collection complete
756 I: sleep 9498 seconds
757 I: finishing Android Wide Profiling daemon
759 // check to make sure log excerpt matches
760 compareLogMessages(mock_perfprofdutils_getlogged(),
761 expected, "BasicRunWithLivePerf", true);
764 TEST_F(PerfProfdTest, CallChainRunWithLivePerf)
767 // Callchain profiles are only supported on certain devices.
768 // For now this test is stubbed out except when run on "angler".
770 char propBuf[PROPERTY_VALUE_MAX];
772 property_get("ro.hardware", propBuf, "");
773 if (strcmp(propBuf, "angler")) {
778 // Collect a callchain profile, so as to exercise the code in
779 // perf_data post-processing that digests callchains.
781 PerfProfdRunner runner;
782 std::string ddparam("destination_directory="); ddparam += dest_dir;
783 runner.addToConfig(ddparam);
784 std::string cfparam("config_directory="); cfparam += test_dir;
785 runner.addToConfig(cfparam);
786 runner.addToConfig("main_loop_iterations=1");
787 runner.addToConfig("use_fixed_seed=12345678");
788 runner.addToConfig("max_unprocessed_profiles=100");
789 runner.addToConfig("collection_interval=9999");
790 runner.addToConfig("stack_profile=1");
791 runner.addToConfig("sample_duration=2");
793 // Create semaphore file
794 runner.create_semaphore_file();
797 int daemon_main_return_code = runner.invoke();
799 // Check return code from daemon
800 EXPECT_EQ(0, daemon_main_return_code);
802 // Read and decode the resulting perf.data.encoded file
803 wireless_android_play_playlog::AndroidPerfProfile encodedProfile;
804 readEncodedProfile("CallChainRunWithLivePerf", encodedProfile);
806 // Examine what we get back. Since it's a live profile, we can't
807 // really do much in terms of verifying the contents.
808 EXPECT_LT(0, encodedProfile.programs_size());
810 // Verify log contents
811 const std::string expected = RAW_RESULT(
812 I: starting Android Wide Profiling daemon
813 I: config file path set to /data/nativetest/perfprofd_test/perfprofd.conf
814 I: random seed set to 12345678
816 I: initiating profile collection
817 I: profile collection complete
818 I: sleep 9325 seconds
819 I: finishing Android Wide Profiling daemon
821 // check to make sure log excerpt matches
822 compareLogMessages(mock_perfprofdutils_getlogged(),
823 expected, "CallChainRunWithLivePerf", true);
826 int main(int argc, char **argv) {
827 executable_path = argv[0];
828 // switch to / before starting testing (perfprofd
829 // should be location-independent)
831 testing::InitGoogleTest(&argc, argv);
832 return RUN_ALL_TESTS();