OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/trace_config.h" | 6 #include "base/trace_event/trace_config.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
7 | 8 |
8 namespace base { | 9 namespace base { |
9 namespace trace_event { | 10 namespace trace_event { |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 const char kDefaultTraceConfigString[] = | 14 const char kDefaultTraceConfigString[] = |
14 "{" | 15 "{" |
15 "\"enable_argument_filter\":false," | 16 "\"enable_argument_filter\":false," |
16 "\"enable_sampling\":false," | 17 "\"enable_sampling\":false," |
17 "\"enable_systrace\":false," | 18 "\"enable_systrace\":false," |
18 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," | 19 "\"excluded_categories\":[\"*Debug\",\"*Test\"]," |
19 "\"record_mode\":\"record-until-full\"" | 20 "\"record_mode\":\"record-until-full\"" |
20 "}"; | 21 "}"; |
21 | 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 |
22 } // namespace | 61 } // namespace |
23 | 62 |
24 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { | 63 TEST(TraceConfigTest, TraceConfigFromValidLegacyFormat) { |
25 // From trace options strings | 64 // From trace options strings |
26 TraceConfig config("", "record-until-full"); | 65 TraceConfig config("", "record-until-full"); |
27 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); | 66 EXPECT_EQ(RECORD_UNTIL_FULL, config.GetTraceRecordMode()); |
28 EXPECT_FALSE(config.IsSamplingEnabled()); | 67 EXPECT_FALSE(config.IsSamplingEnabled()); |
29 EXPECT_FALSE(config.IsSystraceEnabled()); | 68 EXPECT_FALSE(config.IsSystraceEnabled()); |
30 EXPECT_FALSE(config.IsArgumentFilterEnabled()); | 69 EXPECT_FALSE(config.IsArgumentFilterEnabled()); |
31 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); | 70 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str()); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 tc.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE); | 520 tc.SetTraceRecordMode(RECORD_AS_MUCH_AS_POSSIBLE); |
482 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); | 521 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, tc.GetTraceRecordMode()); |
483 | 522 |
484 tc.EnableSampling(); | 523 tc.EnableSampling(); |
485 EXPECT_TRUE(tc.IsSamplingEnabled()); | 524 EXPECT_TRUE(tc.IsSamplingEnabled()); |
486 | 525 |
487 tc.EnableSystrace(); | 526 tc.EnableSystrace(); |
488 EXPECT_TRUE(tc.IsSystraceEnabled()); | 527 EXPECT_TRUE(tc.IsSystraceEnabled()); |
489 } | 528 } |
490 | 529 |
| 530 TEST(TraceConfigTest, TraceConfigFromMemoryConfigString) { |
| 531 TraceConfig tc(kMemoryDumpTraceConfigString); |
| 532 EXPECT_STREQ(kMemoryDumpTraceConfigString, tc.ToString().c_str()); |
| 533 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
| 534 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
| 535 |
| 536 EXPECT_EQ(200u, tc.memory_dump_config_[0].periodic_interval_ms); |
| 537 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::LOW, |
| 538 tc.memory_dump_config_[0].level_of_detail); |
| 539 |
| 540 EXPECT_EQ(2000u, tc.memory_dump_config_[1].periodic_interval_ms); |
| 541 EXPECT_EQ(MemoryDumpArgs::LevelOfDetail::HIGH, |
| 542 tc.memory_dump_config_[1].level_of_detail); |
| 543 } |
| 544 |
| 545 TEST(TraceConfigTest, EmptyMemoryDumpConfigTest) { |
| 546 // Empty trigger list should also be specified when converting back to string. |
| 547 TraceConfig tc(kTraceConfigStringWithEmptyTriggers); |
| 548 EXPECT_STREQ(kTraceConfigStringWithEmptyTriggers, tc.ToString().c_str()); |
| 549 EXPECT_EQ(0u, tc.memory_dump_config_.size()); |
| 550 } |
| 551 |
| 552 TEST(TraceConfigTest, LegacyStringToMemoryDumpConfig) { |
| 553 TraceConfig tc(MemoryDumpManager::kTraceCategory, ""); |
| 554 EXPECT_TRUE(tc.IsCategoryGroupEnabled(MemoryDumpManager::kTraceCategory)); |
| 555 EXPECT_NE(std::string::npos, tc.ToString().find("memory_dump_config")); |
| 556 EXPECT_EQ(2u, tc.memory_dump_config_.size()); |
| 557 } |
| 558 |
491 } // namespace trace_event | 559 } // namespace trace_event |
492 } // namespace base | 560 } // namespace base |
OLD | NEW |