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

Side by Side Diff: base/test/trace_event_analyzer.h

Issue 2716023002: Add some changes to TraceAnalyzer to improve analysis (Closed)
Patch Set: Add some changes to TraceAnalyzer to improve analysis Created 3 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
« no previous file with comments | « no previous file | base/test/trace_event_analyzer.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 // Use trace_analyzer::Query and trace_analyzer::TraceAnalyzer to search for 5 // Use trace_analyzer::Query and trace_analyzer::TraceAnalyzer to search for
6 // specific trace events that were generated by the trace_event.h API. 6 // specific trace events that were generated by the trace_event.h API.
7 // 7 //
8 // Basic procedure: 8 // Basic procedure:
9 // - Get trace events JSON string from base::trace_event::TraceLog. 9 // - Get trace events JSON string from base::trace_event::TraceLog.
10 // - Create TraceAnalyzer with JSON string. 10 // - Create TraceAnalyzer with JSON string.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 std::string id; 167 std::string id;
168 168
169 // All numbers and bool values from TraceEvent args are cast to double. 169 // All numbers and bool values from TraceEvent args are cast to double.
170 // bool becomes 1.0 (true) or 0.0 (false). 170 // bool becomes 1.0 (true) or 0.0 (false).
171 std::map<std::string, double> arg_numbers; 171 std::map<std::string, double> arg_numbers;
172 std::map<std::string, std::string> arg_strings; 172 std::map<std::string, std::string> arg_strings;
173 std::map<std::string, std::unique_ptr<base::Value>> arg_values; 173 std::map<std::string, std::unique_ptr<base::Value>> arg_values;
174 174
175 // The other event associated with this event (or NULL). 175 // The other event associated with this event (or NULL).
176 const TraceEvent* other_event; 176 const TraceEvent* other_event;
177
178 // A back-link for |other_event|. That is, if other_event is not null, then
179 // |event->other_event->prev_event == event| is always true.
180 const TraceEvent* prev_event;
177 }; 181 };
178 182
179 typedef std::vector<const TraceEvent*> TraceEventVector; 183 typedef std::vector<const TraceEvent*> TraceEventVector;
180 184
181 class Query { 185 class Query {
182 public: 186 public:
183 Query(const Query& query); 187 Query(const Query& query);
184 188
185 ~Query(); 189 ~Query();
186 190
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // Number arguments include types double, int and bool. 348 // Number arguments include types double, int and bool.
345 static Query OtherHasNumberArg(const std::string& arg_name) { 349 static Query OtherHasNumberArg(const std::string& arg_name) {
346 return Query(OTHER_HAS_NUMBER_ARG, arg_name); 350 return Query(OTHER_HAS_NUMBER_ARG, arg_name);
347 } 351 }
348 352
349 // Evaluates to arg value (string or number). 353 // Evaluates to arg value (string or number).
350 static Query OtherArg(const std::string& arg_name) { 354 static Query OtherArg(const std::string& arg_name) {
351 return Query(OTHER_ARG, arg_name); 355 return Query(OTHER_ARG, arg_name);
352 } 356 }
353 357
358 // Access the associated prev_event's members:
359
360 static Query PrevPid() { return Query(PREV_PID); }
361
362 static Query PrevTid() { return Query(PREV_TID); }
363
364 static Query PrevTime() { return Query(PREV_TIME); }
365
366 static Query PrevPhase() { return Query(PREV_PHASE); }
367
368 static Query PrevCategory() { return Query(PREV_CATEGORY); }
369
370 static Query PrevName() { return Query(PREV_NAME); }
371
372 static Query PrevId() { return Query(PREV_ID); }
373
374 static Query PrevPidIs(int process_id) {
375 return Query(PREV_PID) == Query::Int(process_id);
376 }
377
378 static Query PrevTidIs(int thread_id) {
379 return Query(PREV_TID) == Query::Int(thread_id);
380 }
381
382 static Query PrevThreadIs(const TraceEvent::ProcessThreadID& thread) {
383 return PrevPidIs(thread.process_id) && PrevTidIs(thread.thread_id);
384 }
385
386 static Query PrevTimeIs(double timestamp) {
387 return Query(PREV_TIME) == Query::Double(timestamp);
388 }
389
390 static Query PrevPhaseIs(char phase) {
391 return Query(PREV_PHASE) == Query::Phase(phase);
392 }
393
394 static Query PrevCategoryIs(const std::string& category) {
395 return Query(PREV_CATEGORY) == Query::String(category);
396 }
397
398 static Query PrevNameIs(const std::string& name) {
399 return Query(PREV_NAME) == Query::String(name);
400 }
401
402 static Query PrevIdIs(const std::string& id) {
403 return Query(PREV_ID) == Query::String(id);
404 }
405
406 // Evaluates to true if arg exists and is a string.
407 static Query PrevHasStringArg(const std::string& arg_name) {
408 return Query(PREV_HAS_STRING_ARG, arg_name);
409 }
410
411 // Evaluates to true if arg exists and is a number.
412 // Number arguments include types double, int and bool.
413 static Query PrevHasNumberArg(const std::string& arg_name) {
414 return Query(PREV_HAS_NUMBER_ARG, arg_name);
415 }
416
417 // Evaluates to arg value (string or number).
418 static Query PrevArg(const std::string& arg_name) {
419 return Query(PREV_ARG, arg_name);
420 }
421
354 //////////////////////////////////////////////////////////////// 422 ////////////////////////////////////////////////////////////////
355 // Common queries: 423 // Common queries:
356 424
357 // Find BEGIN events that have a corresponding END event. 425 // Find BEGIN events that have a corresponding END event.
358 static Query MatchBeginWithEnd() { 426 static Query MatchBeginWithEnd() {
359 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) && 427 return (Query(EVENT_PHASE) == Query::Phase(TRACE_EVENT_PHASE_BEGIN)) &&
360 Query(EVENT_HAS_OTHER); 428 Query(EVENT_HAS_OTHER);
361 } 429 }
362 430
363 // Find COMPLETE events. 431 // Find COMPLETE events.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 EVENT_DURATION, 499 EVENT_DURATION,
432 EVENT_COMPLETE_DURATION, 500 EVENT_COMPLETE_DURATION,
433 EVENT_PHASE, 501 EVENT_PHASE,
434 EVENT_CATEGORY, 502 EVENT_CATEGORY,
435 EVENT_NAME, 503 EVENT_NAME,
436 EVENT_ID, 504 EVENT_ID,
437 EVENT_HAS_STRING_ARG, 505 EVENT_HAS_STRING_ARG,
438 EVENT_HAS_NUMBER_ARG, 506 EVENT_HAS_NUMBER_ARG,
439 EVENT_ARG, 507 EVENT_ARG,
440 EVENT_HAS_OTHER, 508 EVENT_HAS_OTHER,
509 EVENT_HAS_PREV,
510
441 OTHER_PID, 511 OTHER_PID,
442 OTHER_TID, 512 OTHER_TID,
443 OTHER_TIME, 513 OTHER_TIME,
444 OTHER_PHASE, 514 OTHER_PHASE,
445 OTHER_CATEGORY, 515 OTHER_CATEGORY,
446 OTHER_NAME, 516 OTHER_NAME,
447 OTHER_ID, 517 OTHER_ID,
448 OTHER_HAS_STRING_ARG, 518 OTHER_HAS_STRING_ARG,
449 OTHER_HAS_NUMBER_ARG, 519 OTHER_HAS_NUMBER_ARG,
450 OTHER_ARG, 520 OTHER_ARG,
521
522 PREV_PID,
523 PREV_TID,
524 PREV_TIME,
525 PREV_PHASE,
526 PREV_CATEGORY,
527 PREV_NAME,
528 PREV_ID,
529 PREV_HAS_STRING_ARG,
530 PREV_HAS_NUMBER_ARG,
531 PREV_ARG,
532
533 OTHER_FIRST_MEMBER = OTHER_PID,
534 OTHER_LAST_MEMBER = OTHER_ARG,
535
536 PREV_FIRST_MEMBER = PREV_PID,
537 PREV_LAST_MEMBER = PREV_ARG,
451 }; 538 };
452 539
453 enum Operator { 540 enum Operator {
454 OP_INVALID, 541 OP_INVALID,
455 // Boolean operators: 542 // Boolean operators:
456 OP_EQ, 543 OP_EQ,
457 OP_NE, 544 OP_NE,
458 OP_LT, 545 OP_LT,
459 OP_LE, 546 OP_LE,
460 OP_GT, 547 OP_GT,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 bool is_value() const { return type_ != QUERY_BOOLEAN_OPERATOR; } 616 bool is_value() const { return type_ != QUERY_BOOLEAN_OPERATOR; }
530 617
531 bool is_unary_operator() const { 618 bool is_unary_operator() const {
532 return operator_ == OP_NOT || operator_ == OP_NEGATE; 619 return operator_ == OP_NOT || operator_ == OP_NEGATE;
533 } 620 }
534 621
535 bool is_comparison_operator() const { 622 bool is_comparison_operator() const {
536 return operator_ != OP_INVALID && operator_ < OP_AND; 623 return operator_ != OP_INVALID && operator_ < OP_AND;
537 } 624 }
538 625
626 static const TraceEvent* SelectTargetEvent(const TraceEvent* ev,
627 TraceEventMember member);
628
539 const Query& left() const; 629 const Query& left() const;
540 const Query& right() const; 630 const Query& right() const;
541 631
542 QueryType type_; 632 QueryType type_;
543 Operator operator_; 633 Operator operator_;
544 scoped_refptr<QueryNode> left_; 634 scoped_refptr<QueryNode> left_;
545 scoped_refptr<QueryNode> right_; 635 scoped_refptr<QueryNode> right_;
546 TraceEventMember member_; 636 TraceEventMember member_;
547 double number_; 637 double number_;
548 std::string string_; 638 std::string string_;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // An end event will match the most recent begin event with the same name, 672 // An end event will match the most recent begin event with the same name,
583 // category, process ID and thread ID. This matches what is shown in 673 // category, process ID and thread ID. This matches what is shown in
584 // about:tracing. After association, the BEGIN event will point to the 674 // about:tracing. After association, the BEGIN event will point to the
585 // matching END event, but the END event will not point to the BEGIN event. 675 // matching END event, but the END event will not point to the BEGIN event.
586 void AssociateBeginEndEvents(); 676 void AssociateBeginEndEvents();
587 677
588 // Associate ASYNC_BEGIN, ASYNC_STEP and ASYNC_END events with each other. 678 // Associate ASYNC_BEGIN, ASYNC_STEP and ASYNC_END events with each other.
589 // An ASYNC_END event will match the most recent ASYNC_BEGIN or ASYNC_STEP 679 // An ASYNC_END event will match the most recent ASYNC_BEGIN or ASYNC_STEP
590 // event with the same name, category, and ID. This creates a singly linked 680 // event with the same name, category, and ID. This creates a singly linked
591 // list of ASYNC_BEGIN->ASYNC_STEP...->ASYNC_END. 681 // list of ASYNC_BEGIN->ASYNC_STEP...->ASYNC_END.
592 void AssociateAsyncBeginEndEvents(); 682 // |match_pid| - If true, will only match async events which are running
683 // under the same process ID, otherwise will allow linking
684 // async events from different processes.
685 void AssociateAsyncBeginEndEvents(bool match_pid = true);
593 686
594 // AssociateEvents can be used to customize event associations by setting the 687 // AssociateEvents can be used to customize event associations by setting the
595 // other_event member of TraceEvent. This should be used to associate two 688 // other_event member of TraceEvent. This should be used to associate two
596 // INSTANT events. 689 // INSTANT events.
597 // 690 //
598 // The assumptions are: 691 // The assumptions are:
599 // - |first| events occur before |second| events. 692 // - |first| events occur before |second| events.
600 // - the closest matching |second| event is the correct match. 693 // - the closest matching |second| event is the correct match.
601 // 694 //
602 // |first| - Eligible |first| events match this query. 695 // |first| - Eligible |first| events match this query.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 801
709 // Count all matches. 802 // Count all matches.
710 static inline size_t CountMatches(const TraceEventVector& events, 803 static inline size_t CountMatches(const TraceEventVector& events,
711 const Query& query) { 804 const Query& query) {
712 return CountMatches(events, query, 0u, events.size()); 805 return CountMatches(events, query, 0u, events.size());
713 } 806 }
714 807
715 } // namespace trace_analyzer 808 } // namespace trace_analyzer
716 809
717 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ 810 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_
OLDNEW
« no previous file with comments | « no previous file | base/test/trace_event_analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698