| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 ~QueryNode(); | 404 ~QueryNode(); |
| 405 | 405 |
| 406 Query query_; | 406 Query query_; |
| 407 }; | 407 }; |
| 408 | 408 |
| 409 // TraceAnalyzer helps tests search for trace events. | 409 // TraceAnalyzer helps tests search for trace events. |
| 410 class TraceAnalyzer { | 410 class TraceAnalyzer { |
| 411 public: | 411 public: |
| 412 typedef std::vector<const TraceEvent*> TraceEventVector; | 412 typedef std::vector<const TraceEvent*> TraceEventVector; |
| 413 | 413 |
| 414 struct Stats { |
| 415 double min_us; |
| 416 double max_us; |
| 417 double mean_us; |
| 418 double standard_deviation_us; |
| 419 }; |
| 420 |
| 414 ~TraceAnalyzer(); | 421 ~TraceAnalyzer(); |
| 415 | 422 |
| 416 // Use trace events from JSON string generated by tracing API. | 423 // Use trace events from JSON string generated by tracing API. |
| 417 // Returns non-NULL if the JSON is successfully parsed. | 424 // Returns non-NULL if the JSON is successfully parsed. |
| 418 static TraceAnalyzer* Create(const std::string& json_events) | 425 static TraceAnalyzer* Create(const std::string& json_events) |
| 419 WARN_UNUSED_RESULT; | 426 WARN_UNUSED_RESULT; |
| 420 | 427 |
| 421 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) | 428 // Associate BEGIN and END events with each other. This allows Query(OTHER_*) |
| 422 // to access the associated event and enables Query(EVENT_DURATION). | 429 // to access the associated event and enables Query(EVENT_DURATION). |
| 423 // An end event will match the most recent begin event with the same name, | 430 // An end event will match the most recent begin event with the same name, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 454 const Query& match); | 461 const Query& match); |
| 455 | 462 |
| 456 // Find all events that match query and replace output vector. | 463 // Find all events that match query and replace output vector. |
| 457 size_t FindEvents(const Query& query, TraceEventVector* output); | 464 size_t FindEvents(const Query& query, TraceEventVector* output); |
| 458 | 465 |
| 459 // Helper method: find first event that matches query | 466 // Helper method: find first event that matches query |
| 460 const TraceEvent* FindOneEvent(const Query& query); | 467 const TraceEvent* FindOneEvent(const Query& query); |
| 461 | 468 |
| 462 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); | 469 const std::string& GetThreadName(const TraceEvent::ProcessThreadID& thread); |
| 463 | 470 |
| 471 // Calculate min/max/mean and standard deviation from the times between |
| 472 // adjacent events. |
| 473 static bool GetRateStats(const TraceEventVector& events, Stats* stats); |
| 474 |
| 464 private: | 475 private: |
| 465 TraceAnalyzer(); | 476 TraceAnalyzer(); |
| 466 | 477 |
| 467 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; | 478 bool SetEvents(const std::string& json_events) WARN_UNUSED_RESULT; |
| 468 | 479 |
| 469 // Read metadata (thread names, etc) from events. | 480 // Read metadata (thread names, etc) from events. |
| 470 void ParseMetadata(); | 481 void ParseMetadata(); |
| 471 | 482 |
| 472 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; | 483 std::map<TraceEvent::ProcessThreadID, std::string> thread_names_; |
| 473 std::vector<TraceEvent> raw_events_; | 484 std::vector<TraceEvent> raw_events_; |
| 474 bool allow_assocation_changes_; | 485 bool allow_assocation_changes_; |
| 475 | 486 |
| 476 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); | 487 DISALLOW_COPY_AND_ASSIGN(TraceAnalyzer); |
| 477 }; | 488 }; |
| 478 | 489 |
| 479 } // namespace trace_analyzer | 490 } // namespace trace_analyzer |
| 480 | 491 |
| 481 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ | 492 #endif // BASE_TEST_TRACE_EVENT_ANALYZER_H_ |
| OLD | NEW |