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

Side by Side Diff: src/counters.h

Issue 6685088: Merge isolates to bleeding_edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 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 | « src/conversions.cc ('k') | src/counters.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 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 20 matching lines...) Expand all
31 #include "../include/v8.h" 31 #include "../include/v8.h"
32 #include "allocation.h" 32 #include "allocation.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 // StatsCounters is an interface for plugging into external 37 // StatsCounters is an interface for plugging into external
38 // counters for monitoring. Counters can be looked up and 38 // counters for monitoring. Counters can be looked up and
39 // manipulated by name. 39 // manipulated by name.
40 40
41 class StatsTable : public AllStatic { 41 class StatsTable {
42 public: 42 public:
43 // Register an application-defined function where 43 // Register an application-defined function where
44 // counters can be looked up. 44 // counters can be looked up.
45 static void SetCounterFunction(CounterLookupCallback f) { 45 void SetCounterFunction(CounterLookupCallback f) {
46 lookup_function_ = f; 46 lookup_function_ = f;
47 } 47 }
48 48
49 // Register an application-defined function to create 49 // Register an application-defined function to create
50 // a histogram for passing to the AddHistogramSample function 50 // a histogram for passing to the AddHistogramSample function
51 static void SetCreateHistogramFunction(CreateHistogramCallback f) { 51 void SetCreateHistogramFunction(CreateHistogramCallback f) {
52 create_histogram_function_ = f; 52 create_histogram_function_ = f;
53 } 53 }
54 54
55 // Register an application-defined function to add a sample 55 // Register an application-defined function to add a sample
56 // to a histogram created with CreateHistogram function 56 // to a histogram created with CreateHistogram function
57 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) { 57 void SetAddHistogramSampleFunction(AddHistogramSampleCallback f) {
58 add_histogram_sample_function_ = f; 58 add_histogram_sample_function_ = f;
59 } 59 }
60 60
61 static bool HasCounterFunction() { 61 bool HasCounterFunction() const {
62 return lookup_function_ != NULL; 62 return lookup_function_ != NULL;
63 } 63 }
64 64
65 // Lookup the location of a counter by name. If the lookup 65 // Lookup the location of a counter by name. If the lookup
66 // is successful, returns a non-NULL pointer for writing the 66 // is successful, returns a non-NULL pointer for writing the
67 // value of the counter. Each thread calling this function 67 // value of the counter. Each thread calling this function
68 // may receive a different location to store it's counter. 68 // may receive a different location to store it's counter.
69 // The return value must not be cached and re-used across 69 // The return value must not be cached and re-used across
70 // threads, although a single thread is free to cache it. 70 // threads, although a single thread is free to cache it.
71 static int* FindLocation(const char* name) { 71 int* FindLocation(const char* name) {
72 if (!lookup_function_) return NULL; 72 if (!lookup_function_) return NULL;
73 return lookup_function_(name); 73 return lookup_function_(name);
74 } 74 }
75 75
76 // Create a histogram by name. If the create is successful, 76 // Create a histogram by name. If the create is successful,
77 // returns a non-NULL pointer for use with AddHistogramSample 77 // returns a non-NULL pointer for use with AddHistogramSample
78 // function. min and max define the expected minimum and maximum 78 // function. min and max define the expected minimum and maximum
79 // sample values. buckets is the maximum number of buckets 79 // sample values. buckets is the maximum number of buckets
80 // that the samples will be grouped into. 80 // that the samples will be grouped into.
81 static void* CreateHistogram(const char* name, 81 void* CreateHistogram(const char* name,
82 int min, 82 int min,
83 int max, 83 int max,
84 size_t buckets) { 84 size_t buckets) {
85 if (!create_histogram_function_) return NULL; 85 if (!create_histogram_function_) return NULL;
86 return create_histogram_function_(name, min, max, buckets); 86 return create_histogram_function_(name, min, max, buckets);
87 } 87 }
88 88
89 // Add a sample to a histogram created with the CreateHistogram 89 // Add a sample to a histogram created with the CreateHistogram
90 // function. 90 // function.
91 static void AddHistogramSample(void* histogram, int sample) { 91 void AddHistogramSample(void* histogram, int sample) {
92 if (!add_histogram_sample_function_) return; 92 if (!add_histogram_sample_function_) return;
93 return add_histogram_sample_function_(histogram, sample); 93 return add_histogram_sample_function_(histogram, sample);
94 } 94 }
95 95
96 private: 96 private:
97 static CounterLookupCallback lookup_function_; 97 StatsTable();
98 static CreateHistogramCallback create_histogram_function_; 98
99 static AddHistogramSampleCallback add_histogram_sample_function_; 99 CounterLookupCallback lookup_function_;
100 CreateHistogramCallback create_histogram_function_;
101 AddHistogramSampleCallback add_histogram_sample_function_;
102
103 friend class Isolate;
104
105 DISALLOW_COPY_AND_ASSIGN(StatsTable);
100 }; 106 };
101 107
102 // StatsCounters are dynamically created values which can be tracked in 108 // StatsCounters are dynamically created values which can be tracked in
103 // the StatsTable. They are designed to be lightweight to create and 109 // the StatsTable. They are designed to be lightweight to create and
104 // easy to use. 110 // easy to use.
105 // 111 //
106 // Internally, a counter represents a value in a row of a StatsTable. 112 // Internally, a counter represents a value in a row of a StatsTable.
107 // The row has a 32bit value for each process/thread in the table and also 113 // The row has a 32bit value for each process/thread in the table and also
108 // a name (stored in the table metadata). Since the storage location can be 114 // a name (stored in the table metadata). Since the storage location can be
109 // thread-specific, this class cannot be shared across threads. 115 // thread-specific, this class cannot be shared across threads.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ASSERT(loc != NULL); 165 ASSERT(loc != NULL);
160 return loc; 166 return loc;
161 } 167 }
162 168
163 protected: 169 protected:
164 // Returns the cached address of this counter location. 170 // Returns the cached address of this counter location.
165 int* GetPtr() { 171 int* GetPtr() {
166 if (lookup_done_) 172 if (lookup_done_)
167 return ptr_; 173 return ptr_;
168 lookup_done_ = true; 174 lookup_done_ = true;
169 ptr_ = StatsTable::FindLocation(name_); 175 ptr_ = FindLocationInStatsTable();
170 return ptr_; 176 return ptr_;
171 } 177 }
178
179 private:
180 int* FindLocationInStatsTable() const;
172 }; 181 };
173 182
174 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; 183 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 };
175 struct StatsCounterTimer { 184 struct StatsCounterTimer {
176 StatsCounter counter_; 185 StatsCounter counter_;
177 186
178 int64_t start_time_; 187 int64_t start_time_;
179 int64_t stop_time_; 188 int64_t stop_time_;
180 189
181 // Start the timer. 190 // Start the timer.
(...skipping 27 matching lines...) Expand all
209 // Returns true if the timer is running. 218 // Returns true if the timer is running.
210 bool Running() { 219 bool Running() {
211 return (histogram_ != NULL) && (start_time_ != 0) && (stop_time_ == 0); 220 return (histogram_ != NULL) && (start_time_ != 0) && (stop_time_ == 0);
212 } 221 }
213 222
214 protected: 223 protected:
215 // Returns the handle to the histogram. 224 // Returns the handle to the histogram.
216 void* GetHistogram() { 225 void* GetHistogram() {
217 if (!lookup_done_) { 226 if (!lookup_done_) {
218 lookup_done_ = true; 227 lookup_done_ = true;
219 histogram_ = StatsTable::CreateHistogram(name_, 0, 10000, 50); 228 histogram_ = CreateHistogram();
220 } 229 }
221 return histogram_; 230 return histogram_;
222 } 231 }
232
233 private:
234 void* CreateHistogram() const;
223 }; 235 };
224 236
225 // Helper class for scoping a HistogramTimer. 237 // Helper class for scoping a HistogramTimer.
226 class HistogramTimerScope BASE_EMBEDDED { 238 class HistogramTimerScope BASE_EMBEDDED {
227 public: 239 public:
228 explicit HistogramTimerScope(HistogramTimer* timer) : 240 explicit HistogramTimerScope(HistogramTimer* timer) :
229 timer_(timer) { 241 timer_(timer) {
230 timer_->Start(); 242 timer_->Start();
231 } 243 }
232 ~HistogramTimerScope() { 244 ~HistogramTimerScope() {
233 timer_->Stop(); 245 timer_->Stop();
234 } 246 }
235 private: 247 private:
236 HistogramTimer* timer_; 248 HistogramTimer* timer_;
237 }; 249 };
238 250
239 251
240 } } // namespace v8::internal 252 } } // namespace v8::internal
241 253
242 #endif // V8_COUNTERS_H_ 254 #endif // V8_COUNTERS_H_
OLDNEW
« no previous file with comments | « src/conversions.cc ('k') | src/counters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698