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         "\"excluded_categories\":["
23         "\"*\""
24         "],"
25         "\"included_categories\":["
26         "\"%s\""
27         "],"
28         "\"memory_dump_config\":{"
29         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
30         "\"heap_profiler_options\":{"
31         "\"breakdown_threshold_bytes\":2048"
32         "},"
33         "\"triggers\":["
34         "{"
35         "\"mode\":\"light\","
36         "\"periodic_interval_ms\":%d"
37         "},"
38         "{"
39         "\"mode\":\"detailed\","
40         "\"periodic_interval_ms\":%d"
41         "}"
42         "]"
43         "},"
44         "\"record_mode\":\"record-until-full\""
45         "}",
46         MemoryDumpManager::kTraceCategory, light_period, heavy_period);
47     ;
48   }
49 
GetTraceConfig_PeriodicTriggers(int light_period,int heavy_period)50   static std::string GetTraceConfig_PeriodicTriggers(int light_period,
51                                                      int heavy_period) {
52     return StringPrintf(
53         "{"
54         "\"enable_argument_filter\":false,"
55         "\"enable_systrace\":false,"
56         "\"excluded_categories\":["
57         "\"*\""
58         "],"
59         "\"included_categories\":["
60         "\"%s\""
61         "],"
62         "\"memory_dump_config\":{"
63         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
64         "\"heap_profiler_options\":{"
65         "\"breakdown_threshold_bytes\":2048"
66         "},"
67         "\"triggers\":["
68         "{"
69         "\"min_time_between_dumps_ms\":%d,"
70         "\"mode\":\"light\","
71         "\"type\":\"periodic_interval\""
72         "},"
73         "{"
74         "\"min_time_between_dumps_ms\":%d,"
75         "\"mode\":\"detailed\","
76         "\"type\":\"periodic_interval\""
77         "}"
78         "]"
79         "},"
80         "\"record_mode\":\"record-until-full\""
81         "}",
82         MemoryDumpManager::kTraceCategory, light_period, heavy_period);
83   }
84 
GetTraceConfig_EmptyTriggers()85   static std::string GetTraceConfig_EmptyTriggers() {
86     return StringPrintf(
87         "{"
88         "\"enable_argument_filter\":false,"
89         "\"enable_systrace\":false,"
90         "\"excluded_categories\":["
91         "\"*\""
92         "],"
93         "\"included_categories\":["
94         "\"%s\""
95         "],"
96         "\"memory_dump_config\":{"
97         "\"allowed_dump_modes\":[\"background\",\"light\",\"detailed\"],"
98         "\"triggers\":["
99         "]"
100         "},"
101         "\"record_mode\":\"record-until-full\""
102         "}",
103         MemoryDumpManager::kTraceCategory);
104   }
105 
GetTraceConfig_NoTriggers()106   static std::string GetTraceConfig_NoTriggers() {
107     return StringPrintf(
108         "{"
109         "\"enable_argument_filter\":false,"
110         "\"enable_systrace\":false,"
111         "\"excluded_categories\":["
112         "\"*\""
113         "],"
114         "\"included_categories\":["
115         "\"%s\""
116         "],"
117         "\"record_mode\":\"record-until-full\""
118         "}",
119         MemoryDumpManager::kTraceCategory);
120   }
121 
GetTraceConfig_BackgroundTrigger(int period_ms)122   static std::string GetTraceConfig_BackgroundTrigger(int period_ms) {
123     return StringPrintf(
124         "{"
125         "\"enable_argument_filter\":false,"
126         "\"enable_systrace\":false,"
127         "\"excluded_categories\":["
128         "\"*\""
129         "],"
130         "\"included_categories\":["
131         "\"%s\""
132         "],"
133         "\"memory_dump_config\":{"
134         "\"allowed_dump_modes\":[\"background\"],"
135         "\"triggers\":["
136         "{"
137         "\"min_time_between_dumps_ms\":%d,"
138         "\"mode\":\"background\","
139         "\"type\":\"periodic_interval\""
140         "}"
141         "]"
142         "},"
143         "\"record_mode\":\"record-until-full\""
144         "}",
145         MemoryDumpManager::kTraceCategory, period_ms);
146   }
147 };
148 
149 }  // namespace trace_event
150 }  // namespace base
151 
152 #endif  // BASE_TRACE_EVENT_TRACE_CONFIG_MEMORY_TEST_UTIL_H_
153