UMA server currently receives 2.5M unique thread name hashes in tracked objects. This huge number comes from generated thread names like "BrowserBlockingWorker1/23857". To reasonably reduce this number, this CL maps names like: "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*".
Same thing is done by chrome://profile page.
BUG=342004
Review URL: https://codereview.chromium.org/131453016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249916 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 1801066d..80815f4 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -257,6 +257,23 @@
}
}
+// Maps a thread name by replacing trailing sequence of digits with "*".
+// Examples:
+// 1. "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*"
+// 2. "Chrome_IOThread" => "Chrome_IOThread"
+std::string MapThreadName(const std::string& thread_name) {
+ size_t i = thread_name.length();
+
+ while (i > 0 && isdigit(thread_name[i - 1])) {
+ --i;
+ }
+
+ if (i == thread_name.length())
+ return thread_name;
+
+ return thread_name.substr(0, i) + '*';
+}
+
void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
int process_type,
ProfilerEventProto* performance_profile) {
@@ -267,9 +284,9 @@
ProfilerEventProto::TrackedObject* tracked_object =
performance_profile->add_tracked_object();
tracked_object->set_birth_thread_name_hash(
- MetricsLogBase::Hash(it->birth.thread_name));
+ MetricsLogBase::Hash(MapThreadName(it->birth.thread_name)));
tracked_object->set_exec_thread_name_hash(
- MetricsLogBase::Hash(it->death_thread_name));
+ MetricsLogBase::Hash(MapThreadName(it->death_thread_name)));
tracked_object->set_source_file_name_hash(
MetricsLogBase::Hash(it->birth.location.file_name));
tracked_object->set_source_function_name_hash(