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

Unified Diff: src/counters.cc

Issue 2887193002: Create a thread safe version of StatsCounters and use. (Closed)
Patch Set: fix nits of mtrofin Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: src/counters.cc
diff --git a/src/counters.cc b/src/counters.cc
index d1a1a44c9f9c65cfa7f7dd93f2b5c24c4d3b3c52..327b203afbefc2ac94c7bc84f2713f791c9776f8 100644
--- a/src/counters.cc
+++ b/src/counters.cc
@@ -20,11 +20,61 @@ StatsTable::StatsTable()
create_histogram_function_(NULL),
add_histogram_sample_function_(NULL) {}
+void StatsTable::SetCounterFunction(CounterLookupCallback f, Isolate* isolate) {
+ lookup_function_ = f;
+ if (!isolate->InitializeCounters()) isolate->counters()->ResetCounters();
+}
-int* StatsCounter::FindLocationInStatsTable() const {
+int* StatsCounterBase::FindLocationInStatsTable() const {
return isolate_->stats_table()->FindLocation(name_);
}
+StatsCounterThreadSafe::StatsCounterThreadSafe(Isolate* isolate,
+ const char* name)
+ : StatsCounterBase(isolate, name) {
+ GetPtr();
+}
+
+void StatsCounterThreadSafe::Set(int Value) {
+ if (ptr_) {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ SetLoc(ptr_, Value);
+ }
+}
+
+void StatsCounterThreadSafe::Increment() {
+ if (ptr_) {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ IncrementLoc(ptr_);
+ }
+}
+
+void StatsCounterThreadSafe::Increment(int value) {
+ if (ptr_) {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ IncrementLoc(ptr_, value);
+ }
+}
+
+void StatsCounterThreadSafe::Decrement() {
+ if (ptr_) {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ DecrementLoc(ptr_);
+ }
+}
+
+void StatsCounterThreadSafe::Decrement(int value) {
+ if (ptr_) {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ DecrementLoc(ptr_, value);
+ }
+}
+
+int* StatsCounterThreadSafe::GetPtr() {
+ base::LockGuard<base::Mutex> Guard(&mutex_);
+ ptr_ = FindLocationInStatsTable();
+ return ptr_;
+}
void Histogram::AddSample(int sample) {
if (Enabled()) {
@@ -60,8 +110,14 @@ void HistogramTimer::Stop() {
Logger::CallEventLogger(isolate(), name(), Logger::END, true);
}
-
-Counters::Counters(Isolate* isolate) {
+Counters::Counters(Isolate* isolate)
+ :
+// clang format off
+#define SC(name, caption) name##_(isolate, "c:" #caption),
+ STATS_COUNTER_TS_LIST(SC)
+#undef SC
+ // clang format on
+ runtime_call_stats_() {
static const struct {
Histogram Counters::*member;
const char* caption;
@@ -200,13 +256,16 @@ Counters::Counters(Isolate* isolate) {
}
}
-
void Counters::ResetCounters() {
#define SC(name, caption) name##_.Reset();
STATS_COUNTER_LIST_1(SC)
STATS_COUNTER_LIST_2(SC)
#undef SC
+#define SC(name, caption) name##_.Reset();
+ STATS_COUNTER_TS_LIST(SC)
+#undef SC
+
#define SC(name) \
count_of_##name##_.Reset(); \
size_of_##name##_.Reset();

Powered by Google App Engine
This is Rietveld 408576698