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

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

Issue 8678035: Add TraceAnalyzer support for calculating common event rate statistics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/test/trace_event_analyzer.h ('k') | base/test/trace_event_analyzer_unittest.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) 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 #include "base/test/trace_event_analyzer.h" 5 #include "base/test/trace_event_analyzer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return output.front(); 706 return output.front();
707 return NULL; 707 return NULL;
708 } 708 }
709 709
710 const std::string& TraceAnalyzer::GetThreadName( 710 const std::string& TraceAnalyzer::GetThreadName(
711 const TraceEvent::ProcessThreadID& thread) { 711 const TraceEvent::ProcessThreadID& thread) {
712 // If thread is not found, just add and return empty string. 712 // If thread is not found, just add and return empty string.
713 return thread_names_[thread]; 713 return thread_names_[thread];
714 } 714 }
715 715
716 bool TraceAnalyzer::GetRateStats(const TraceEventVector& events, Stats* stats) {
717 // Need at least 3 events to calculate rate stats.
718 if (events.size() < 3) {
719 LOG(ERROR) << "Not enough events: " << events.size();
720 return false;
721 }
722
723 std::vector<double> deltas;
724 double delta_sum = 0.0;
725 size_t num_deltas = events.size() - 1;
726 for (size_t i = 0; i < num_deltas; ++i) {
727 double delta = events[i + 1]->timestamp - events[i]->timestamp;
728 if (delta < 0.0) {
729 LOG(ERROR) << "Events are out of order";
730 return false;
731 }
732 deltas.push_back(delta);
733 delta_sum += delta;
734 }
735
736 stats->min_us = *std::min_element(deltas.begin(), deltas.end());
737 stats->max_us = *std::max_element(deltas.begin(), deltas.end());
738 stats->mean_us = delta_sum / static_cast<double>(num_deltas);
739
740 double sum_mean_offsets_squared = 0.0;
741 for (size_t i = 0; i < num_deltas; ++i) {
742 double offset = fabs(deltas[i] - stats->mean_us);
743 sum_mean_offsets_squared += offset * offset;
744 }
745 stats->standard_deviation_us =
746 sum_mean_offsets_squared / static_cast<double>(num_deltas - 1);
747
748 return true;
749 }
750
716 void TraceAnalyzer::ParseMetadata() { 751 void TraceAnalyzer::ParseMetadata() {
717 for (size_t i = 0; i < raw_events_.size(); ++i) { 752 for (size_t i = 0; i < raw_events_.size(); ++i) {
718 TraceEvent& this_event = raw_events_[i]; 753 TraceEvent& this_event = raw_events_[i];
719 // Check for thread name metadata. 754 // Check for thread name metadata.
720 if (this_event.phase != TRACE_EVENT_PHASE_METADATA || 755 if (this_event.phase != TRACE_EVENT_PHASE_METADATA ||
721 this_event.name != "thread_name") 756 this_event.name != "thread_name")
722 continue; 757 continue;
723 std::map<std::string, std::string>::const_iterator string_it = 758 std::map<std::string, std::string>::const_iterator string_it =
724 this_event.arg_strings.find("name"); 759 this_event.arg_strings.find("name");
725 if (string_it != this_event.arg_strings.end()) 760 if (string_it != this_event.arg_strings.end())
726 thread_names_[this_event.thread] = string_it->second; 761 thread_names_[this_event.thread] = string_it->second;
727 } 762 }
728 } 763 }
729 764
730 } // namespace trace_analyzer 765 } // namespace trace_analyzer
731 766
OLDNEW
« no previous file with comments | « base/test/trace_event_analyzer.h ('k') | base/test/trace_event_analyzer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698