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

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

Issue 9580021: Add test for RAF-spinning with no damage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: marking test flaky for initial commit to be safe Created 8 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/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) 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/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 #include <set> 9 #include <set>
10 10
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 continue; 810 continue;
811 std::map<std::string, std::string>::const_iterator string_it = 811 std::map<std::string, std::string>::const_iterator string_it =
812 this_event.arg_strings.find("name"); 812 this_event.arg_strings.find("name");
813 if (string_it != this_event.arg_strings.end()) 813 if (string_it != this_event.arg_strings.end())
814 thread_names_[this_event.thread] = string_it->second; 814 thread_names_[this_event.thread] = string_it->second;
815 } 815 }
816 } 816 }
817 817
818 // TraceEventVector utility functions. 818 // TraceEventVector utility functions.
819 819
820 bool GetRateStats(const TraceEventVector& events, RateStats* stats) { 820 bool GetRateStats(const TraceEventVector& events,
821 RateStats* stats,
822 const RateStatsOptions* options) {
821 CHECK(stats); 823 CHECK(stats);
822 // Need at least 3 events to calculate rate stats. 824 // Need at least 3 events to calculate rate stats.
823 if (events.size() < 3) { 825 const size_t kMinEvents = 3;
826 if (events.size() < kMinEvents) {
824 LOG(ERROR) << "Not enough events: " << events.size(); 827 LOG(ERROR) << "Not enough events: " << events.size();
825 return false; 828 return false;
826 } 829 }
827 830
828 std::vector<double> deltas; 831 std::vector<double> deltas;
829 double delta_sum = 0.0;
830 size_t num_deltas = events.size() - 1; 832 size_t num_deltas = events.size() - 1;
831 for (size_t i = 0; i < num_deltas; ++i) { 833 for (size_t i = 0; i < num_deltas; ++i) {
832 double delta = events.at(i + 1)->timestamp - events.at(i)->timestamp; 834 double delta = events.at(i + 1)->timestamp - events.at(i)->timestamp;
833 if (delta < 0.0) { 835 if (delta < 0.0) {
834 LOG(ERROR) << "Events are out of order"; 836 LOG(ERROR) << "Events are out of order";
835 return false; 837 return false;
836 } 838 }
837 deltas.push_back(delta); 839 deltas.push_back(delta);
838 delta_sum += delta;
839 } 840 }
840 841
842 std::sort(deltas.begin(), deltas.end());
843
844 if (options) {
845 if (options->trim_min + options->trim_max > events.size() - kMinEvents) {
846 LOG(ERROR) << "Attempt to trim too many events";
847 return false;
848 }
849 deltas.erase(deltas.begin(), deltas.begin() + options->trim_min);
850 deltas.erase(deltas.end() - options->trim_max, deltas.end());
851 }
852
853 num_deltas = deltas.size();
854 double delta_sum = 0.0;
855 for (size_t i = 0; i < num_deltas; ++i)
856 delta_sum += deltas[i];
857
841 stats->min_us = *std::min_element(deltas.begin(), deltas.end()); 858 stats->min_us = *std::min_element(deltas.begin(), deltas.end());
842 stats->max_us = *std::max_element(deltas.begin(), deltas.end()); 859 stats->max_us = *std::max_element(deltas.begin(), deltas.end());
843 stats->mean_us = delta_sum / static_cast<double>(num_deltas); 860 stats->mean_us = delta_sum / static_cast<double>(num_deltas);
844 861
845 double sum_mean_offsets_squared = 0.0; 862 double sum_mean_offsets_squared = 0.0;
846 for (size_t i = 0; i < num_deltas; ++i) { 863 for (size_t i = 0; i < num_deltas; ++i) {
847 double offset = fabs(deltas[i] - stats->mean_us); 864 double offset = fabs(deltas[i] - stats->mean_us);
848 sum_mean_offsets_squared += offset * offset; 865 sum_mean_offsets_squared += offset * offset;
849 } 866 }
850 stats->standard_deviation_us = 867 stats->standard_deviation_us =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 size_t count = 0u; 951 size_t count = 0u;
935 for (size_t i = begin_position; i < end_position; ++i) { 952 for (size_t i = begin_position; i < end_position; ++i) {
936 if (query.Evaluate(*events.at(i))) 953 if (query.Evaluate(*events.at(i)))
937 ++count; 954 ++count;
938 } 955 }
939 return count; 956 return count;
940 } 957 }
941 958
942 } // namespace trace_analyzer 959 } // namespace trace_analyzer
943 960
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