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

Unified Diff: third_party/WebKit/Source/wtf/HashTable.cpp

Issue 2511983003: HashTable: bring per-table stats tracking back to life. (Closed)
Patch Set: switch dump defaults back to disabled Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashTable.cpp
diff --git a/third_party/WebKit/Source/wtf/HashTable.cpp b/third_party/WebKit/Source/wtf/HashTable.cpp
index a67b8440b4f529d46293bb8f8710349a24aedcee..0a8c37029a51ded193b3ededb5d80df370e2f45a 100644
--- a/third_party/WebKit/Source/wtf/HashTable.cpp
+++ b/third_party/WebKit/Source/wtf/HashTable.cpp
@@ -26,29 +26,47 @@
namespace WTF {
-int HashTableStats::numAccesses;
-int HashTableStats::numCollisions;
-int HashTableStats::collisionGraph[4096];
-int HashTableStats::maxCollisions;
-int HashTableStats::numRehashes;
-int HashTableStats::numRemoves;
-int HashTableStats::numReinserts;
-
static Mutex& hashTableStatsMutex() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex);
return mutex;
}
+HashTableStats& HashTableStats::instance() {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(HashTableStats, stats, new HashTableStats);
+ return stats;
+}
+
+void HashTableStats::copy(const HashTableStats* other) {
+ numAccesses = other->numAccesses;
+ numRehashes = other->numRehashes;
+ numRemoves = other->numRemoves;
+ numReinserts = other->numReinserts;
+
+ maxCollisions = other->maxCollisions;
+ numCollisions = other->numCollisions;
+ memcpy(collisionGraph, other->collisionGraph, sizeof(collisionGraph));
+}
+
void HashTableStats::recordCollisionAtCount(int count) {
- MutexLocker lock(hashTableStatsMutex());
+ // The global hash table singleton needs to be atomically updated.
+ bool isGlobalSingleton = this == &instance();
+ if (isGlobalSingleton)
+ hashTableStatsMutex().lock();
+
if (count > maxCollisions)
maxCollisions = count;
numCollisions++;
collisionGraph[count]++;
+
+ if (isGlobalSingleton)
+ hashTableStatsMutex().unlock();
}
void HashTableStats::dumpStats() {
- MutexLocker lock(hashTableStatsMutex());
+ // Lock the global hash table singleton while dumping.
+ bool isGlobalSingleton = this == &instance();
+ if (isGlobalSingleton)
+ hashTableStatsMutex().lock();
dataLogF("\nWTF::HashTable statistics\n\n");
dataLogF("%d accesses\n", numAccesses);
@@ -65,6 +83,9 @@ void HashTableStats::dumpStats() {
}
dataLogF("%d rehashes\n", numRehashes);
dataLogF("%d reinserts\n", numReinserts);
+
+ if (isGlobalSingleton)
+ hashTableStatsMutex().unlock();
}
} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698