Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: base/test/trace_event_analyzer_unittest.cc

Issue 12252058: Add a |scope| argument to TRACE_EVENT_INSTANT* and require its presence. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix builds 2 Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | cc/animation/animation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/debug/trace_event_unittest.h" 6 #include "base/debug/trace_event_unittest.h"
7 #include "base/test/trace_event_analyzer.h" 7 #include "base/test/trace_event_analyzer.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 EXPECT_FALSE(event_arg1.Evaluate(other)); 201 EXPECT_FALSE(event_arg1.Evaluate(other));
202 EXPECT_FALSE(event_arg2.Evaluate(other)); 202 EXPECT_FALSE(event_arg2.Evaluate(other));
203 EXPECT_FALSE(event_has_other.Evaluate(other)); 203 EXPECT_FALSE(event_has_other.Evaluate(other));
204 } 204 }
205 205
206 TEST_F(TraceEventAnalyzerTest, BooleanOperators) { 206 TEST_F(TraceEventAnalyzerTest, BooleanOperators) {
207 ManualSetUp(); 207 ManualSetUp();
208 208
209 BeginTracing(); 209 BeginTracing();
210 { 210 {
211 TRACE_EVENT_INSTANT1("cat1", "name1", "num", 1); 211 TRACE_EVENT_INSTANT1("cat1", "name1", TRACE_EVENT_SCOPE_THREAD, "num", 1);
212 TRACE_EVENT_INSTANT1("cat1", "name2", "num", 2); 212 TRACE_EVENT_INSTANT1("cat1", "name2", TRACE_EVENT_SCOPE_THREAD, "num", 2);
213 TRACE_EVENT_INSTANT1("cat2", "name3", "num", 3); 213 TRACE_EVENT_INSTANT1("cat2", "name3", TRACE_EVENT_SCOPE_THREAD, "num", 3);
214 TRACE_EVENT_INSTANT1("cat2", "name4", "num", 4); 214 TRACE_EVENT_INSTANT1("cat2", "name4", TRACE_EVENT_SCOPE_THREAD, "num", 4);
215 } 215 }
216 EndTracing(); 216 EndTracing();
217 217
218 scoped_ptr<TraceAnalyzer> 218 scoped_ptr<TraceAnalyzer>
219 analyzer(TraceAnalyzer::Create(output_.json_output)); 219 analyzer(TraceAnalyzer::Create(output_.json_output));
220 ASSERT_TRUE(!!analyzer.get()); 220 ASSERT_TRUE(!!analyzer.get());
221 221
222 TraceEventVector found; 222 TraceEventVector found;
223 223
224 // == 224 // ==
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 EXPECT_STREQ("name2", found[0]->name.c_str()); 286 EXPECT_STREQ("name2", found[0]->name.c_str());
287 EXPECT_STREQ("name4", found[1]->name.c_str()); 287 EXPECT_STREQ("name4", found[1]->name.c_str());
288 } 288 }
289 289
290 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) { 290 TEST_F(TraceEventAnalyzerTest, ArithmeticOperators) {
291 ManualSetUp(); 291 ManualSetUp();
292 292
293 BeginTracing(); 293 BeginTracing();
294 { 294 {
295 // These events are searched for: 295 // These events are searched for:
296 TRACE_EVENT_INSTANT2("cat1", "math1", "a", 10, "b", 5); 296 TRACE_EVENT_INSTANT2("cat1", "math1", TRACE_EVENT_SCOPE_THREAD,
297 TRACE_EVENT_INSTANT2("cat1", "math2", "a", 10, "b", 10); 297 "a", 10, "b", 5);
298 TRACE_EVENT_INSTANT2("cat1", "math2", TRACE_EVENT_SCOPE_THREAD,
299 "a", 10, "b", 10);
298 // Extra events that never match, for noise: 300 // Extra events that never match, for noise:
299 TRACE_EVENT_INSTANT2("noise", "math3", "a", 1, "b", 3); 301 TRACE_EVENT_INSTANT2("noise", "math3", TRACE_EVENT_SCOPE_THREAD,
300 TRACE_EVENT_INSTANT2("noise", "math4", "c", 10, "d", 5); 302 "a", 1, "b", 3);
303 TRACE_EVENT_INSTANT2("noise", "math4", TRACE_EVENT_SCOPE_THREAD,
304 "c", 10, "d", 5);
301 } 305 }
302 EndTracing(); 306 EndTracing();
303 307
304 scoped_ptr<TraceAnalyzer> 308 scoped_ptr<TraceAnalyzer>
305 analyzer(TraceAnalyzer::Create(output_.json_output)); 309 analyzer(TraceAnalyzer::Create(output_.json_output));
306 ASSERT_TRUE(analyzer.get()); 310 ASSERT_TRUE(analyzer.get());
307 311
308 TraceEventVector found; 312 TraceEventVector found;
309 313
310 // Verify that arithmetic operators function: 314 // Verify that arithmetic operators function:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 analyzer->FindEvents(-Query::EventArg("b") == Query::Int(-10), &found); 346 analyzer->FindEvents(-Query::EventArg("b") == Query::Int(-10), &found);
343 EXPECT_EQ(1u, found.size()); 347 EXPECT_EQ(1u, found.size());
344 EXPECT_STREQ("math2", found.front()->name.c_str()); 348 EXPECT_STREQ("math2", found.front()->name.c_str());
345 } 349 }
346 350
347 TEST_F(TraceEventAnalyzerTest, StringPattern) { 351 TEST_F(TraceEventAnalyzerTest, StringPattern) {
348 ManualSetUp(); 352 ManualSetUp();
349 353
350 BeginTracing(); 354 BeginTracing();
351 { 355 {
352 TRACE_EVENT_INSTANT0("cat1", "name1"); 356 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD);
353 TRACE_EVENT_INSTANT0("cat1", "name2"); 357 TRACE_EVENT_INSTANT0("cat1", "name2", TRACE_EVENT_SCOPE_THREAD);
354 TRACE_EVENT_INSTANT0("cat1", "no match"); 358 TRACE_EVENT_INSTANT0("cat1", "no match", TRACE_EVENT_SCOPE_THREAD);
355 TRACE_EVENT_INSTANT0("cat1", "name3x"); 359 TRACE_EVENT_INSTANT0("cat1", "name3x", TRACE_EVENT_SCOPE_THREAD);
356 } 360 }
357 EndTracing(); 361 EndTracing();
358 362
359 scoped_ptr<TraceAnalyzer> 363 scoped_ptr<TraceAnalyzer>
360 analyzer(TraceAnalyzer::Create(output_.json_output)); 364 analyzer(TraceAnalyzer::Create(output_.json_output));
361 ASSERT_TRUE(analyzer.get()); 365 ASSERT_TRUE(analyzer.get());
362 366
363 TraceEventVector found; 367 TraceEventVector found;
364 368
365 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found); 369 analyzer->FindEvents(Query::EventName() == Query::Pattern("name?"), &found);
(...skipping 20 matching lines...) Expand all
386 // We will search for events that have a duration of greater than 90% of the 390 // We will search for events that have a duration of greater than 90% of the
387 // sleep time, so that there is no flakiness. 391 // sleep time, so that there is no flakiness.
388 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10; 392 int duration_cutoff_us = (kSleepTime.InMicroseconds() * 9) / 10;
389 393
390 BeginTracing(); 394 BeginTracing();
391 { 395 {
392 TRACE_EVENT0("cat1", "name1"); // found by duration query 396 TRACE_EVENT0("cat1", "name1"); // found by duration query
393 TRACE_EVENT0("noise", "name2"); // not searched for, just noise 397 TRACE_EVENT0("noise", "name2"); // not searched for, just noise
394 { 398 {
395 TRACE_EVENT0("cat2", "name3"); // found by duration query 399 TRACE_EVENT0("cat2", "name3"); // found by duration query
396 TRACE_EVENT_INSTANT0("noise", "name4"); // not searched for, just noise 400 // next event not searched for, just noise
401 TRACE_EVENT_INSTANT0("noise", "name4", TRACE_EVENT_SCOPE_THREAD);
397 base::debug::HighResSleepForTraceTest(kSleepTime); 402 base::debug::HighResSleepForTraceTest(kSleepTime);
398 TRACE_EVENT0("cat2", "name5"); // not found (duration too short) 403 TRACE_EVENT0("cat2", "name5"); // not found (duration too short)
399 } 404 }
400 } 405 }
401 EndTracing(); 406 EndTracing();
402 407
403 scoped_ptr<TraceAnalyzer> 408 scoped_ptr<TraceAnalyzer>
404 analyzer(TraceAnalyzer::Create(output_.json_output)); 409 analyzer(TraceAnalyzer::Create(output_.json_output));
405 ASSERT_TRUE(analyzer.get()); 410 ASSERT_TRUE(analyzer.get());
406 analyzer->AssociateBeginEndEvents(); 411 analyzer->AssociateBeginEndEvents();
(...skipping 12 matching lines...) Expand all
419 } 424 }
420 425
421 // Test AssociateBeginEndEvents 426 // Test AssociateBeginEndEvents
422 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) { 427 TEST_F(TraceEventAnalyzerTest, BeginEndAssocations) {
423 ManualSetUp(); 428 ManualSetUp();
424 429
425 BeginTracing(); 430 BeginTracing();
426 { 431 {
427 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin 432 TRACE_EVENT_END0("cat1", "name1"); // does not match out of order begin
428 TRACE_EVENT0("cat1", "name2"); 433 TRACE_EVENT0("cat1", "name2");
429 TRACE_EVENT_INSTANT0("cat1", "name3"); 434 TRACE_EVENT_INSTANT0("cat1", "name3", TRACE_EVENT_SCOPE_THREAD);
430 TRACE_EVENT_BEGIN0("cat1", "name1"); 435 TRACE_EVENT_BEGIN0("cat1", "name1");
431 } 436 }
432 EndTracing(); 437 EndTracing();
433 438
434 scoped_ptr<TraceAnalyzer> 439 scoped_ptr<TraceAnalyzer>
435 analyzer(TraceAnalyzer::Create(output_.json_output)); 440 analyzer(TraceAnalyzer::Create(output_.json_output));
436 ASSERT_TRUE(analyzer.get()); 441 ASSERT_TRUE(analyzer.get());
437 analyzer->AssociateBeginEndEvents(); 442 analyzer->AssociateBeginEndEvents();
438 443
439 TraceEventVector found; 444 TraceEventVector found;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 477
473 // Test AssociateAsyncBeginEndEvents 478 // Test AssociateAsyncBeginEndEvents
474 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocations) { 479 TEST_F(TraceEventAnalyzerTest, AsyncBeginEndAssocations) {
475 ManualSetUp(); 480 ManualSetUp();
476 481
477 BeginTracing(); 482 BeginTracing();
478 { 483 {
479 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xA); // no match / out of order 484 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xA); // no match / out of order
480 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB); 485 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xB);
481 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC); 486 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xC);
482 TRACE_EVENT_INSTANT0("cat1", "name1"); // noise 487 TRACE_EVENT_INSTANT0("cat1", "name1", TRACE_EVENT_SCOPE_THREAD); // noise
483 TRACE_EVENT0("cat1", "name1"); // noise 488 TRACE_EVENT0("cat1", "name1"); // noise
484 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB); 489 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xB);
485 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC); 490 TRACE_EVENT_ASYNC_END0("cat1", "name1", 0xC);
486 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order 491 TRACE_EVENT_ASYNC_BEGIN0("cat1", "name1", 0xA); // no match / out of order
487 } 492 }
488 EndTracing(); 493 EndTracing();
489 494
490 scoped_ptr<TraceAnalyzer> 495 scoped_ptr<TraceAnalyzer>
491 analyzer(TraceAnalyzer::Create(output_.json_output)); 496 analyzer(TraceAnalyzer::Create(output_.json_output));
492 ASSERT_TRUE(analyzer.get()); 497 ASSERT_TRUE(analyzer.get());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 557 }
553 558
554 // Test that the TraceAnalyzer custom associations work. 559 // Test that the TraceAnalyzer custom associations work.
555 TEST_F(TraceEventAnalyzerTest, CustomAssociations) { 560 TEST_F(TraceEventAnalyzerTest, CustomAssociations) {
556 ManualSetUp(); 561 ManualSetUp();
557 562
558 // Add events that begin/end in pipelined ordering with unique ID parameter 563 // Add events that begin/end in pipelined ordering with unique ID parameter
559 // to match up the begin/end pairs. 564 // to match up the begin/end pairs.
560 BeginTracing(); 565 BeginTracing();
561 { 566 {
562 TRACE_EVENT_INSTANT1("cat1", "end", "id", 1); // no begin match 567 // no begin match
563 TRACE_EVENT_INSTANT1("cat2", "begin", "id", 2); // end is cat4 568 TRACE_EVENT_INSTANT1("cat1", "end", TRACE_EVENT_SCOPE_THREAD, "id", 1);
564 TRACE_EVENT_INSTANT1("cat3", "begin", "id", 3); // end is cat5 569 // end is cat4
565 TRACE_EVENT_INSTANT1("cat4", "end", "id", 2); 570 TRACE_EVENT_INSTANT1("cat2", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 2);
566 TRACE_EVENT_INSTANT1("cat5", "end", "id", 3); 571 // end is cat5
567 TRACE_EVENT_INSTANT1("cat6", "begin", "id", 1); // no end match 572 TRACE_EVENT_INSTANT1("cat3", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 3);
573 TRACE_EVENT_INSTANT1("cat4", "end", TRACE_EVENT_SCOPE_THREAD, "id", 2);
574 TRACE_EVENT_INSTANT1("cat5", "end", TRACE_EVENT_SCOPE_THREAD, "id", 3);
575 // no end match
576 TRACE_EVENT_INSTANT1("cat6", "begin", TRACE_EVENT_SCOPE_THREAD, "id", 1);
568 } 577 }
569 EndTracing(); 578 EndTracing();
570 579
571 scoped_ptr<TraceAnalyzer> 580 scoped_ptr<TraceAnalyzer>
572 analyzer(TraceAnalyzer::Create(output_.json_output)); 581 analyzer(TraceAnalyzer::Create(output_.json_output));
573 ASSERT_TRUE(analyzer.get()); 582 ASSERT_TRUE(analyzer.get());
574 583
575 // begin, end, and match queries to find proper begin/end pairs. 584 // begin, end, and match queries to find proper begin/end pairs.
576 Query begin(Query::EventName() == Query::String("begin")); 585 Query begin(Query::EventName() == Query::String("begin"));
577 Query end(Query::EventName() == Query::String("end")); 586 Query end(Query::EventName() == Query::String("end"));
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true))); 829 EXPECT_EQ(num_events, CountMatches(event_ptrs, Query::Bool(true)));
821 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true), 830 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, Query::Bool(true),
822 1, num_events)); 831 1, num_events));
823 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one)); 832 EXPECT_EQ(1u, CountMatches(event_ptrs, query_one));
824 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one)); 833 EXPECT_EQ(num_events - 1, CountMatches(event_ptrs, !query_one));
825 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named)); 834 EXPECT_EQ(num_named, CountMatches(event_ptrs, query_named));
826 } 835 }
827 836
828 837
829 } // namespace trace_analyzer 838 } // namespace trace_analyzer
OLDNEW
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | cc/animation/animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698