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

Unified Diff: chrome/browser/metrics/metrics_log.cc

Issue 217483006: Normalizing source file names before calculating hash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/metrics_log.cc
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index f9721f4a5c02158cb7821e1970d187d1c4e01631..cf42ba3cdc51773fbfe8d29402413acd55653680 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -273,6 +273,23 @@ std::string MapThreadName(const std::string& thread_name) {
return thread_name.substr(0, i) + '*';
}
+// Normalizes a source filename (which is platform- and build-method-dependent)
+// by extracting the last component of the full file name.
+// Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" =>
+// "chrome_main.cc".
+std::string NormalizeFileName(const std::string& file_name) {
jar (doing other things) 2014/03/29 00:32:25 nit: The argument is actually a const char* (befor
vadimt 2014/03/29 00:45:50 In fact, the parameter std::string. https://code.g
jar (doing other things) 2014/03/29 00:52:23 Ah... quite correct. SGTM.
+ size_t i = file_name.length();
+
+ while (i > 0) {
+ const char current_character = file_name[i - 1];
+ if (current_character == '/' || current_character == '\\')
+ break;
+ --i;
+ }
+
+ return file_name.substr(i);
Ilya Sherman 2014/03/29 01:06:49 IMO this method would be clearer if written using
vadimt 2014/03/31 18:10:14 Yeah, but that is much less efficient, since we bu
Ilya Sherman 2014/03/31 23:44:48 I'm not convinced that this is a place where such
vadimt 2014/04/01 18:24:10 Done, but using find_last_of. Looks OK?
+}
+
void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
int process_type,
ProfilerEventProto* performance_profile) {
@@ -287,7 +304,7 @@ void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
tracked_object->set_exec_thread_name_hash(
MetricsLogBase::Hash(MapThreadName(it->death_thread_name)));
tracked_object->set_source_file_name_hash(
- MetricsLogBase::Hash(it->birth.location.file_name));
+ MetricsLogBase::Hash(NormalizeFileName(it->birth.location.file_name)));
jar (doing other things) 2014/03/29 00:32:25 Should we consider expanding the protobuf, and put
vadimt 2014/03/29 00:45:50 Given uselessness of the existing full filename ha
jar (doing other things) 2014/03/29 00:52:23 OK. The old one disambiguates... but I guess if w
tracked_object->set_source_function_name_hash(
MetricsLogBase::Hash(it->birth.location.function_name));
tracked_object->set_source_line_number(it->birth.location.line_number);
« no previous file with comments | « no previous file | chrome/browser/metrics/metrics_log_unittest.cc » ('j') | chrome/browser/metrics/metrics_log_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698