OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 #include <stdio.h> | 4 #include <limits> |
5 | 5 |
6 #include "include/libplatform/v8-tracing.h" | 6 #include "include/libplatform/v8-tracing.h" |
7 #include "src/tracing/trace-event.h" | 7 #include "src/tracing/trace-event.h" |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace platform { | 11 namespace platform { |
12 namespace tracing { | 12 namespace tracing { |
13 | 13 |
14 TEST(TestTraceConfig) { | 14 TEST(TestTraceConfig) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 'Y', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test1", | 135 'Y', tracing_controller.GetCategoryGroupEnabled("v8-cat"), "Test1", |
136 v8::internal::tracing::kGlobalScope, 43, 456, 0, NULL, NULL, NULL, 0, | 136 v8::internal::tracing::kGlobalScope, 43, 456, 0, NULL, NULL, NULL, 0, |
137 55, 66, 110, 55, 77, 88); | 137 55, 66, 110, 55, 77, 88); |
138 writer->AppendTraceEvent(&trace_object); | 138 writer->AppendTraceEvent(&trace_object); |
139 tracing_controller.StopTracing(); | 139 tracing_controller.StopTracing(); |
140 } | 140 } |
141 | 141 |
142 std::string trace_str = stream.str(); | 142 std::string trace_str = stream.str(); |
143 std::string expected_trace_str = | 143 std::string expected_trace_str = |
144 "{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50," | 144 "{\"traceEvents\":[{\"pid\":11,\"tid\":22,\"ts\":100,\"tts\":50," |
145 "\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"args\":{}," | 145 "\"ph\":\"X\",\"cat\":\"v8-cat\",\"name\":\"Test0\",\"dur\":33," |
146 "\"dur\":33,\"tdur\":44},{\"pid\":55,\"tid\":66,\"ts\":110,\"tts\":55," | 146 "\"tdur\":44,\"args\":{}},{\"pid\":55,\"tid\":66,\"ts\":110,\"tts\":55," |
147 "\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":\"Test1\",\"args\":{},\"dur\":" | 147 "\"ph\":\"Y\",\"cat\":\"v8-cat\",\"name\":\"Test1\",\"dur\":77," |
148 "77,\"tdur\":88}]}"; | 148 "\"tdur\":88,\"args\":{}}]}"; |
149 | 149 |
150 CHECK_EQ(expected_trace_str, trace_str); | 150 CHECK_EQ(expected_trace_str, trace_str); |
151 | 151 |
152 i::V8::SetPlatformForTesting(old_platform); | 152 i::V8::SetPlatformForTesting(old_platform); |
153 } | 153 } |
154 | 154 |
155 TEST(TestTracingController) { | 155 TEST(TestTracingController) { |
156 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | 156 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); |
157 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform(); | 157 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform(); |
158 i::V8::SetPlatformForTesting(default_platform); | 158 i::V8::SetPlatformForTesting(default_platform); |
(...skipping 15 matching lines...) Expand all Loading... | |
174 TRACE_EVENT0("v8", "v8.Test3"); | 174 TRACE_EVENT0("v8", "v8.Test3"); |
175 tracing_controller.StopTracing(); | 175 tracing_controller.StopTracing(); |
176 | 176 |
177 CHECK_EQ(2, writer->events().size()); | 177 CHECK_EQ(2, writer->events().size()); |
178 CHECK_EQ(std::string("v8.Test"), writer->events()[0]); | 178 CHECK_EQ(std::string("v8.Test"), writer->events()[0]); |
179 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]); | 179 CHECK_EQ(std::string("v8.Test3"), writer->events()[1]); |
180 | 180 |
181 i::V8::SetPlatformForTesting(old_platform); | 181 i::V8::SetPlatformForTesting(old_platform); |
182 } | 182 } |
183 | 183 |
184 void GetJSONStrings(std::vector<std::string>& ret, std::string str, | |
185 std::string param, std::string start_delim, | |
186 std::string end_delim) { | |
187 size_t pos = str.find(param); | |
188 while (pos != std::string::npos) { | |
189 size_t start_pos = str.find(start_delim, pos + param.length()); | |
190 size_t end_pos = str.find(end_delim, start_pos + 1); | |
191 CHECK_NE(start_pos, std::string::npos); | |
192 CHECK_NE(end_pos, std::string::npos); | |
193 ret.push_back(str.substr(start_pos + 1, end_pos - start_pos - 1)); | |
194 pos = str.find(param, pos + 1); | |
195 } | |
196 } | |
197 | |
198 TEST(TestTracingControllerMultipleArgsAndCopy) { | |
199 std::ostringstream stream; | |
200 v8::Platform* old_platform = i::V8::GetCurrentPlatform(); | |
201 v8::Platform* default_platform = v8::platform::CreateDefaultPlatform(); | |
202 i::V8::SetPlatformForTesting(default_platform); | |
203 | |
204 uint64_t aa = 11; | |
205 unsigned int bb = 22; | |
206 uint16_t cc = 33; | |
207 unsigned char dd = 44; | |
208 int64_t ee = -55; | |
209 int ff = -66; | |
210 int16_t gg = -77; | |
211 signed char hh = -88; | |
212 bool ii1 = true; | |
213 bool ii2 = false; | |
214 double jj1 = 99.0; | |
215 double jj2 = 1e100; | |
216 double jj3 = std::numeric_limits<double>::quiet_NaN(); | |
217 double jj4 = std::numeric_limits<double>::infinity(); | |
218 double jj5 = -std::numeric_limits<double>::infinity(); | |
219 void* kk = &aa; | |
220 const char* ll = "100"; | |
221 std::string mm = "INIT"; | |
222 std::string v8 = "v8"; | |
223 | |
224 // Create a scope for the tracing controller to terminate the trace writer. | |
225 { | |
226 TracingController tracing_controller; | |
227 platform::SetTracingController(default_platform, &tracing_controller); | |
228 TraceWriter* writer = TraceWriter::CreateJSONTraceWriter(stream); | |
229 | |
230 TraceBuffer* ring_buffer = | |
231 TraceBuffer::CreateTraceBufferRingBuffer(1, writer); | |
232 tracing_controller.Initialize(ring_buffer); | |
233 TraceConfig* trace_config = new TraceConfig(); | |
234 trace_config->AddIncludedCategory("v8"); | |
235 tracing_controller.StartTracing(trace_config); | |
236 | |
237 TRACE_EVENT1("v8", "v8.Test.aa", "aa", aa); | |
238 TRACE_EVENT1("v8", "v8.Test.bb", "bb", bb); | |
239 TRACE_EVENT1("v8", "v8.Test.cc", "cc", cc); | |
240 TRACE_EVENT1("v8", "v8.Test.dd", "dd", dd); | |
241 TRACE_EVENT1("v8", "v8.Test.ee", "ee", ee); | |
242 TRACE_EVENT1("v8", "v8.Test.ff", "ff", ff); | |
243 TRACE_EVENT1("v8", "v8.Test.gg", "gg", gg); | |
244 TRACE_EVENT1("v8", "v8.Test.hh", "hh", hh); | |
245 TRACE_EVENT1("v8", "v8.Test.ii", "ii1", ii1); | |
246 TRACE_EVENT1("v8", "v8.Test.ii", "ii2", ii2); | |
247 TRACE_EVENT1("v8", "v8.Test.jj1", "jj1", jj1); | |
248 TRACE_EVENT1("v8", "v8.Test.jj2", "jj2", jj2); | |
249 TRACE_EVENT1("v8", "v8.Test.jj3", "jj3", jj3); | |
250 TRACE_EVENT1("v8", "v8.Test.jj4", "jj4", jj4); | |
251 TRACE_EVENT1("v8", "v8.Test.jj5", "jj5", jj5); | |
252 TRACE_EVENT1("v8", "v8.Test.kk", "kk", kk); | |
253 TRACE_EVENT1("v8", "v8.Test.ll", "ll", ll); | |
254 TRACE_EVENT1("v8", "v8.Test.mm", "mm", TRACE_STR_COPY(mm.c_str())); | |
255 | |
256 TRACE_EVENT2("v8", "v8.Test2.1", "aa", aa, "ll", ll); | |
257 TRACE_EVENT2("v8", "v8.Test2.2", "mm1", TRACE_STR_COPY(mm.c_str()), "mm2", | |
258 TRACE_STR_COPY(mm.c_str())); | |
259 | |
260 // Check copies are correct. | |
261 TRACE_EVENT_COPY_INSTANT0(v8.c_str(), mm.c_str(), TRACE_EVENT_SCOPE_THREAD); | |
mattloring
2016/07/29 01:50:50
Could we additionally add a test that modifies the
rskang
2016/07/29 05:16:26
Yes my bad, the copy test did not test anything pr
| |
262 TRACE_EVENT_COPY_INSTANT1(v8.c_str(), mm.c_str(), TRACE_EVENT_SCOPE_THREAD, | |
263 mm.c_str(), mm.c_str()); | |
264 TRACE_EVENT_COPY_INSTANT2(v8.c_str(), mm.c_str(), TRACE_EVENT_SCOPE_THREAD, | |
fmeawad
2016/07/29 14:32:20
/s/v8.c_str()/"v8"/
Category has to be a constan
rskang
2016/07/29 19:48:13
My bad, the v8.c_str() should not be there. This i
| |
265 mm.c_str(), mm.c_str(), mm.c_str(), mm.c_str()); | |
266 | |
267 tracing_controller.StopTracing(); | |
268 } | |
269 | |
270 std::string trace_str = stream.str(); | |
271 | |
272 std::vector<std::string> all_args, all_names, all_cats; | |
273 GetJSONStrings(all_args, trace_str, "\"args\"", "{", "}"); | |
274 GetJSONStrings(all_names, trace_str, "\"name\"", "\"", "\""); | |
275 GetJSONStrings(all_cats, trace_str, "\"cat\"", "\"", "\""); | |
276 | |
277 mm = "CHANGED"; | |
278 v8 = "v8-changed"; | |
279 | |
280 CHECK_EQ(all_args.size(), 23); | |
281 CHECK_EQ(all_args[0], "\"aa\":11"); | |
282 CHECK_EQ(all_args[1], "\"bb\":22"); | |
283 CHECK_EQ(all_args[2], "\"cc\":33"); | |
284 CHECK_EQ(all_args[3], "\"dd\":44"); | |
285 CHECK_EQ(all_args[4], "\"ee\":-55"); | |
286 CHECK_EQ(all_args[5], "\"ff\":-66"); | |
287 CHECK_EQ(all_args[6], "\"gg\":-77"); | |
288 CHECK_EQ(all_args[7], "\"hh\":-88"); | |
289 CHECK_EQ(all_args[8], "\"ii1\":true"); | |
290 CHECK_EQ(all_args[9], "\"ii2\":false"); | |
291 CHECK_EQ(all_args[10], "\"jj1\":99.0"); | |
292 CHECK_EQ(all_args[11], "\"jj2\":1e+100"); | |
293 CHECK_EQ(all_args[12], "\"jj3\":\"NaN\""); | |
294 CHECK_EQ(all_args[13], "\"jj4\":\"Infinity\""); | |
295 CHECK_EQ(all_args[14], "\"jj5\":\"-Infinity\""); | |
296 std::ostringstream pointer_stream; | |
297 pointer_stream << "\"kk\":\"" << &aa << "\""; | |
298 CHECK_EQ(all_args[15], pointer_stream.str()); | |
299 CHECK_EQ(all_args[16], "\"ll\":\"100\""); | |
300 CHECK_EQ(all_args[17], "\"mm\":\"INIT\""); | |
301 | |
302 CHECK_EQ(all_names[18], "v8.Test2.1"); | |
303 CHECK_EQ(all_args[18], "\"aa\":11,\"ll\":\"100\""); | |
304 CHECK_EQ(all_args[19], "\"mm1\":\"INIT\",\"mm2\":\"INIT\""); | |
305 | |
306 CHECK_EQ(all_names[20], "INIT"); | |
307 CHECK_EQ(all_cats[20], "v8"); | |
308 CHECK_EQ(all_names[21], "INIT"); | |
309 CHECK_EQ(all_cats[21], "v8"); | |
310 CHECK_EQ(all_args[21], "\"INIT\":\"INIT\""); | |
311 CHECK_EQ(all_names[22], "INIT"); | |
312 CHECK_EQ(all_cats[22], "v8"); | |
313 CHECK_EQ(all_args[22], "\"INIT\":\"INIT\",\"INIT\":\"INIT\""); | |
314 | |
315 i::V8::SetPlatformForTesting(old_platform); | |
316 } | |
317 | |
184 } // namespace tracing | 318 } // namespace tracing |
185 } // namespace platform | 319 } // namespace platform |
186 } // namespace v8 | 320 } // namespace v8 |
OLD | NEW |