• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_MEMORY_TEST_UTIL_H_
6 #define BASE_TRACE_EVENT_TRACE_CONFIG_MEMORY_TEST_UTIL_H_
7 
8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/memory_dump_manager.h"
10 
11 namespace base {
12 namespace trace_event {
13 
14 class TraceConfigMemoryTestUtil {
15  public:
GetTraceConfig_LegacyPeriodicTriggers(int light_period,int heavy_period)16   static std::string GetTraceConfig_LegacyPeriodicTriggers(int light_period,
17                                                            int heavy_period) {
18     return StringPrintf(
19         "{"
20         "\"enable_argument_filter\":false,"
21         "\"enable_systrace\":false,"
22         "\"included_categories\":["
23         "\"%s\""
24         "],"
25         "\"memory_dump_config\":{"
26         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
27         "\"heap_profiler_options\":{"
28         "\"breakdown_threshold_bytes\":2048"
29         "},"
30         "\"triggers\":["
31         "{"
32         "\"mode\":\"light\","
33         "\"periodic_interval_ms\":%d"
34         "},"
35         "{"
36         "\"mode\":\"detailed\","
37         "\"periodic_interval_ms\":%d"
38         "}"
39         "]"
40         "},"
41         "\"record_mode\":\"record-until-full\""
42         "}",
43         MemoryDumpManager::kTraceCategory, light_period, heavy_period);
44     ;
45   }
46 
GetTraceConfig_PeriodicTriggers(int light_period,int heavy_period)47   static std::string GetTraceConfig_PeriodicTriggers(int light_period,
48                                                      int heavy_period) {
49     return StringPrintf(
50         "{"
51         "\"enable_argument_filter\":false,"
52         "\"enable_systrace\":false,"
53         "\"included_categories\":["
54         "\"%s\""
55         "],"
56         "\"memory_dump_config\":{"
57         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
58         "\"heap_profiler_options\":{"
59         "\"breakdown_threshold_bytes\":2048"
60         "},"
61         "\"triggers\":["
62         "{"
63         "\"min_time_between_dumps_ms\":%d,"
64         "\"mode\":\"light\","
65         "\"type\":\"periodic_interval\""
66         "},"
67         "{"
68         "\"min_time_between_dumps_ms\":%d,"
69         "\"mode\":\"detailed\","
70         "\"type\":\"periodic_interval\""
71         "}"
72         "]"
73         "},"
74         "\"record_mode\":\"record-until-full\""
75         "}",
76         MemoryDumpManager::kTraceCategory, light_period, heavy_period);
77   }
78 
GetTraceConfig_EmptyTriggers()79   static std::string GetTraceConfig_EmptyTriggers() {
80     return StringPrintf(
81         "{"
82         "\"enable_argument_filter\":false,"
83         "\"enable_systrace\":false,"
84         "\"included_categories\":["
85         "\"%s\""
86         "],"
87         "\"memory_dump_config\":{"
88         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
89         "\"triggers\":["
90         "]"
91         "},"
92         "\"record_mode\":\"record-until-full\""
93         "}",
94         MemoryDumpManager::kTraceCategory);
95   }
96 
GetTraceConfig_NoTriggers()97   static std::string GetTraceConfig_NoTriggers() {
98     return StringPrintf(
99         "{"
100         "\"enable_argument_filter\":false,"
101         "\"enable_systrace\":false,"
102         "\"included_categories\":["
103         "\"%s\""
104         "],"
105         "\"record_mode\":\"record-until-full\""
106         "}",
107         MemoryDumpManager::kTraceCategory);
108   }
109 
GetTraceConfig_BackgroundTrigger(int period_ms)110   static std::string GetTraceConfig_BackgroundTrigger(int period_ms) {
111     return StringPrintf(
112         "{"
113         "\"enable_argument_filter\":false,"
114         "\"enable_systrace\":false,"
115         "\"included_categories\":["
116         "\"%s\""
117         "],"
118         "\"memory_dump_config\":{"
119         "\"allowed_dump_modes\":[\"background\"],"
120         "\"triggers\":["
121         "{"
122         "\"min_time_between_dumps_ms\":%d,"
123         "\"mode\":\"background\","
124         "\"type\":\"periodic_interval\""
125         "}"
126         "]"
127         "},"
128         "\"record_mode\":\"record-until-full\""
129         "}",
130         MemoryDumpManager::kTraceCategory, period_ms);
131   }
132 
GetTraceConfig_PeakDetectionTrigger(int heavy_period)133   static std::string GetTraceConfig_PeakDetectionTrigger(int heavy_period) {
134     return StringPrintf(
135         "{"
136         "\"enable_argument_filter\":false,"
137         "\"enable_systrace\":false,"
138         "\"included_categories\":["
139         "\"%s\""
140         "],"
141         "\"memory_dump_config\":{"
142         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
143         "\"triggers\":["
144         "{"
145         "\"min_time_between_dumps_ms\":%d,"
146         "\"mode\":\"detailed\","
147         "\"type\":\"peak_memory_usage\""
148         "}"
149         "]"
150         "},"
151         "\"record_mode\":\"record-until-full\""
152         "}",
153         MemoryDumpManager::kTraceCategory, heavy_period);
154   }
155 };
156 
157 }  // namespace trace_event
158 }  // namespace base
159 
160 #endif  // BASE_TRACE_EVENT_TRACE_CONFIG_MEMORY_TEST_UTIL_H_
161