OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
6 #include "base/trace_event/trace_config.h" | 6 #include "base/trace_event/trace_config.h" |
| 7 #include "base/trace_event/trace_config_memory_test_util.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 namespace trace_event { | 11 namespace trace_event { |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 const char kDefaultTraceConfigString[] = | 15 const char kDefaultTraceConfigString[] = |
15 "{" | 16 "{" |
16 "\"enable_argument_filter\":false," | 17 "\"enable_argument_filter\":false," |
17 "\"enable_sampling\":false," | 18 "\"enable_sampling\":false," |
18 "\"enable_systrace\":false," | 19 "\"enable_systrace\":false," |
19 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 20 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
20 "\"record_mode\":\"record-until-full\"" | 21 "\"record_mode\":\"record-until-full\"" |
21 "}"; | 22 "}"; |
22 | |
23 const char kMemoryDumpTraceConfigString[] = | |
24 "{" | |
25 "\"enable_argument_filter\":false," | |
26 "\"enable_sampling\":false," | |
27 "\"enable_systrace\":false," | |
28 "\"included_categories\":[" | |
29 "\"disabled-by-default-memory-infra\"" | |
30 "]," | |
31 "\"memory_dump_config\":{" | |
32 "\"triggers\":[" | |
33 "{" | |
34 "\"mode\":\"light\"," | |
35 "\"periodic_interval_ms\":200" | |
36 "}," | |
37 "{" | |
38 "\"mode\":\"detailed\"," | |
39 "\"periodic_interval_ms\":2000" | |
40 "}" | |
41 "]" | |
42 "}," | |
43 "\"record_mode\":\"record-until-full\"" | |
44 "}"; | |
45 | |
46 const char kTraceConfigStringWithEmptyTriggers[] = | |
47 "{" | |
48 "\"enable_argument_filter\":false," | |
49 "\"enable_sampling\":false," | |
50 "\"enable_systrace\":false," | |
51 "\"included_categories\":[" | |
52 "\"disabled-by-default-memory-infra\"" | |
53 "]," | |
54 "\"memory_dump_config\":{" | |
55 "\"triggers\":[" | |
56 "]" | |
57 "}," | |
58 "\"record_mode\":\"record-until-full\"" | |
59 "}"; | |
60 | |
61 } // namespace | 23 } // namespace |
62 | 24 |
63 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { | 25 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { |
64 // From trace options strings | 26 // From trace options strings |
65 TraceConfig config("", "record-until-full"); | 27 TraceConfig config("", "record-until-full"); |
66 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); | 28 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); |
67 EXPECT_FALSE(config.IsSamplingEnabled()); | 29 EXPECT_FALSE(config.IsSamplingEnabled()); |
68 EXPECT_FALSE(config.IsSystraceEnabled()); | 30 EXPECT_FALSE(config.IsSystraceEnabled()); |
69 EXPECT_FALSE(config.IsArgumentFilterEnabled()); | 31 EXPECT_FALSE(config.IsArgumentFilterEnabled()); |
70 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); | 32 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); | 483 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); |
522 | 484 |
523 tc.EnableSampling(); | 485 tc.EnableSampling(); |
524 EXPECT_TRUE(tc.IsSamplingEnabled()); | 486 EXPECT_TRUE(tc.IsSamplingEnabled()); |
525 | 487 |
526 tc.EnableSystrace(); | 488 tc.EnableSystrace(); |
527 EXPECT_TRUE(tc.IsSystraceEnabled()); | 489 EXPECT_TRUE(tc.IsSystraceEnabled()); |
528 } | 490 } |
529 | 491 |
530 TEST(TraceConfigTest, TraceConfigFromMemoryConfigString) { | 492 TEST(TraceConfigTest, TraceConfigFromMemoryConfigString) { |
531 TraceConfig tc(kMemoryDumpTraceConfigString); | 493 std::string tc_str = |
532 EXPECT_STREQ(kMemoryDumpTraceConfigString, tc.ToString().c_str()); | 494 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(200, 2000); |
| 495 TraceConfig tc(tc_str); |
| 496 EXPECT_EQ(tc_str, tc.ToString()); |
533 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); | 497 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
534 EXPECT_EQ(2u, tc.memory_dump_config_.size()); | 498 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
535 | 499 |
536 EXPECT_EQ(200u, tc.memory_dump_config_[0].periodic_interval_ms); | 500 EXPECT_EQ(200u, tc.memory_dump_config_[0].periodic_interval_ms); |
537 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::LOW, | 501 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::LOW, |
538 tc.memory_dump_config_[0].level_of_detail); | 502 tc.memory_dump_config_[0].level_of_detail); |
539 | 503 |
540 EXPECT_EQ(2000u, tc.memory_dump_config_[1].periodic_interval_ms); | 504 EXPECT_EQ(2000u, tc.memory_dump_config_[1].periodic_interval_ms); |
541 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::HIGH, | 505 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::HIGH, |
542 tc.memory_dump_config_[1].level_of_detail); | 506 tc.memory_dump_config_[1].level_of_detail); |
543 } | 507 } |
544 | 508 |
545 TEST(TraceConfigTest, EmptyMemoryDumpConfigTest) { | 509 TEST(TraceConfigTest, EmptyMemoryDumpConfigTest) { |
546 // Empty trigger list should also be specified when converting back to string. | 510 // Empty trigger list should also be specified when converting back to string. |
547 TraceConfig tc(kTraceConfigStringWithEmptyTriggers); | 511 TraceConfig tc(TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers()); |
548 EXPECT_STREQ(kTraceConfigStringWithEmptyTriggers, tc.ToString().c_str()); | 512 EXPECT_EQ(TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers(), |
| 513 tc.ToString()); |
549 EXPECT_EQ(0u, tc.memory_dump_config_.size()); | 514 EXPECT_EQ(0u, tc.memory_dump_config_.size()); |
550 } | 515 } |
551 | 516 |
552 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { | 517 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { |
553 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); | 518 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); |
554 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); | 519 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
555 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); | 520 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); |
556 EXPECT_EQ(2u, tc.memory_dump_config_.size()); | 521 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
557 } | 522 } |
558 | 523 |
559 } // namespace trace_event | 524 } // namespace trace_event |
560 } // namespace base | 525 } // namespace base |
OLD | NEW |