Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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::debug::TraceLog. | 9 // - Get trace events JSON string from base::debug::TraceLog. |
| 10 // - Create TraceAnalyzer with JSON string. | 10 // - Create TraceAnalyzer with JSON string. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 explicit QueryNode(const Query& query); | 408 explicit QueryNode(const Query& query); |
| 409 const Query& query() const { return query_; } | 409 const Query& query() const { return query_; } |
| 410 | 410 |
| 411 private: | 411 private: |
| 412 friend class base::RefCounted<QueryNode>; | 412 friend class base::RefCounted<QueryNode>; |
| 413 ~QueryNode(); | 413 ~QueryNode(); |
| 414 | 414 |
| 415 Query query_; | 415 Query query_; |
| 416 }; | 416 }; |
| 417 | 417 |
| 418 // TraceAnalyzer helps tests search for trace events. | 418 class TraceEventVector : public std::vector<const TraceEvent*> { |
|
Paweł Hajdan Jr.
2011/12/12 17:21:51
Inheritance from std::vector? I'm suspicious. Coul
jbates
2011/12/12 22:00:32
Done.
| |
| 419 class TraceAnalyzer { | |
| 420 public: | 419 public: |
| 421 typedef std::vector<const TraceEvent*> TraceEventVector; | 420 struct RateStats { |
| 422 | |
| 423 struct Stats { | |
| 424 double min_us; | 421 double min_us; |
| 425 double max_us; | 422 double max_us; |
| 426 double mean_us; | 423 double mean_us; |
| 427 double standard_deviation_us; | 424 double standard_deviation_us; |
| 428 }; | 425 }; |
| 429 | 426 |
| 427 // Calculate min/max/mean and standard deviation from the times between | |
| 428 // adjacent events. | |
| 429 bool GetRateStats(RateStats* stats); | |
| 430 | |
| 431 // Starting from |position|, find the first event that matches |query|. | |
| 432 // Returns true if found, false otherwise. | |
| 433 bool FindFirstOf(Query query, | |
| 434 size_t position, | |
| 435 size_t* return_index) const; | |
| 436 | |
| 437 // Starting from |position|, find the last event that matches |query|. | |
| 438 // Returns true if found, false otherwise. | |
| 439 bool FindLastOf(Query query, | |
| 440 size_t position, | |
| 441 size_t* return_index) const; | |
| 442 | |
| 443 // Find the closest events to |position| in time that match |query|. | |
| 444 // return_second_closest may be NULL. Closeness is determined by comparing | |
| 445 // with the event timestamp. | |
| 446 // Returns true if found, false otherwise. If both return parameters are | |
| 447 // requested, both must be found for a successful result. | |
| 448 bool FindClosest(Query query, | |
| 449 size_t position, | |
| 450 size_t* return_closest, | |
| 451 size_t* return_second_closest) const; | |
|
Paweł Hajdan Jr.
2011/12/12 17:21:51
nit: If second_closest is there, why not third_clo
jbates
2011/12/12 22:00:32
Returning a sorted vector did occur to me, but one
| |
| 452 | |
| 453 // Count matches, inclusive of |begin_position|, exclusive of |end_position|. | |
| 454 int CountMatches(Query query, | |
|
Paweł Hajdan Jr.
2011/12/12 17:21:51
nit: If size_t is generally used, why this and met
jbates
2011/12/12 22:00:32
Done.
| |
| 455 size_t begin_position, | |
| 456 size_t end_position) const; | |
| 457 | |
| 458 // Count all matches. | |
| 459 int CountMatches(Query query) const { | |
| 460 return CountMatches(query, 0, size()); | |
| 461 } | |
| 462 }; | |
| 463 | |
| 464 // TraceAnalyzer helps tests search for trace events. | |
| 465 class TraceAnalyzer { | |
| 466 public: | |
| 430 ~TraceAnalyzer(); | 467 ~TraceAnalyzer(); |
| 431 | 468 |
| 432 // Use trace events from JSON string generated by tracing API. | 469 // Use trace events from JSON string generated by tracing API. |
| 433 // Returns non-NULL if the JSON is successfully parsed. | 470 // Returns non-NULL if the JSON is successfully parsed. |
| 434 static TraceAnalyzer* Create(const std::string& json_events) | 471 static TraceAnalyzer* Create(const std::string& json_events) |
| 435 WARN_UNUSED_RESULT; | 472 WARN_UNUSED_RESULT; |
| 436 | 473 |
| 437 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) | 474 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) |
| 438 // to access the associated event and enables Query(EVENT_DURATION). | 475 // to access the associated event and enables Query(EVENT_DURATION). |
| 439 // An end event will match the most recent begin event with the same name, | 476 // An end event will match the most recent begin event with the same name, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 467 // | 504 // |
| 468 // NOTE: AssociateEvents will overwrite existing other_event associations if | 505 // NOTE: AssociateEvents will overwrite existing other_event associations if |
| 469 // the queries pass for events that already had a previous association. | 506 // the queries pass for events that already had a previous association. |
| 470 // | 507 // |
| 471 // After calling FindEvents or FindOneEvent, it is not allowed to call | 508 // After calling FindEvents or FindOneEvent, it is not allowed to call |
| 472 // AssociateEvents again. | 509 // AssociateEvents again. |
| 473 void AssociateEvents(const Query& first, | 510 void AssociateEvents(const Query& first, |
| 474 const Query& second, | 511 const Query& second, |
| 475 const Query& match); | 512 const Query& match); |
| 476 | 513 |
| 514 // For each event, copy its arguments to the other_event argument map. If | |
| 515 // argument name already exists, it will not be overwritten. | |
| 516 void MergeAssociatedEventArgs(); | |
| 517 | |
| 477 // Find all events that match query and replace output vector. | 518 // Find all events that match query and replace output vector. |
| 478 size_t FindEvents(const Query& query, TraceEventVector* output); | 519 size_t FindEvents(const Query& query, TraceEventVector* output); |
| 479 | 520 |
| 480 // Helper method: find first event that matches query | 521 // Helper method: find first event that matches query |
| 481 const TraceEvent* FindOneEvent(const Query& query); | 522 const TraceEvent* FindOneEvent(const Query& query); |
| 482 | 523 |
| 483 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); | 524 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); |
| 484 | 525 |
| 485 // Calculate min/max/mean and standard deviation from the times between | |
| 486 // adjacent events. | |
| 487 static bool GetRateStats(const TraceEventVector& events, Stats* stats); | |
| 488 | |
| 489 private: | 526 private: |
| 490 TraceAnalyzer(); | 527 TraceAnalyzer(); |
| 491 | 528 |
| 492 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; | 529 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; |
| 493 | 530 |
| 494 // Read metadata (thread names, etc) from events. | 531 // Read metadata (thread names, etc) from events. |
| 495 void ParseMetadata(); | 532 void ParseMetadata(); |
| 496 | 533 |
| 497 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; | 534 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; |
| 498 std::vector<TraceEvent> raw_events_; | 535 std::vector<TraceEvent> raw_events_; |
| 499 bool allow_assocation_changes_; | 536 bool allow_assocation_changes_; |
| 500 | 537 |
| 501 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); | 538 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); |
| 502 }; | 539 }; |
| 503 | 540 |
| 504 } // namespace trace_analyzer | 541 } // namespace trace_analyzer |
| 505 | 542 |
| 506 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 543 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| OLD | NEW |