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

Side by Side Diff: base/trace_event/memory_allocator_dump_guid.cc

Issue 1173263004: [tracing] Send unique tracing process id for cross-process memory dumps identification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/memory_allocator_dump_guid.h" 5 #include "base/trace_event/memory_allocator_dump_guid.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 11
11 namespace base { 12 namespace base {
12 namespace trace_event { 13 namespace trace_event {
13 14
15 namespace {
16 int g_unique_child_process_id = MemoryAllocatorDumpGuid::kInvalidChildProcessId;
17
18 uint64 ExpandChildProcessIdAndHash(std::string guid_str) {
dcheng 2015/06/20 00:36:27 const std::string&
Primiano Tucci (use gerrit) 2015/06/20 12:32:31 Note: the string is mangled below. If he passes a
ssid 2015/06/20 13:07:24 Yes, instead of creating a copy, i passed std::str
19 const char kReplaceChildIdStr[] = "$$";
20 size_t pos = guid_str.find(kReplaceChildIdStr);
21 if (pos != std::string::npos) {
22 DCHECK_NE(g_unique_child_process_id,
23 MemoryAllocatorDumpGuid::kInvalidChildProcessId);
24 guid_str.replace(pos, sizeof(kReplaceChildIdStr) - 1,
25 IntToString(g_unique_child_process_id));
26 }
27 return Hash(guid_str);
28 }
29 } // namespace
30
14 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64 guid) : guid_(guid) { 31 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64 guid) : guid_(guid) {
15 } 32 }
16 33
17 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid() 34 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid()
18 : MemoryAllocatorDumpGuid(0u) { 35 : MemoryAllocatorDumpGuid(0u) {
19 } 36 }
20 37
21 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str) 38 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str)
22 : MemoryAllocatorDumpGuid(Hash(guid_str)) { 39 : MemoryAllocatorDumpGuid(ExpandChildProcessIdAndHash(guid_str)) {
40 }
41
42 // static
43 void MemoryAllocatorDumpGuid::SetUniqueChildProcessId(int child_process_id) {
44 DCHECK(g_unique_child_process_id == kInvalidChildProcessId ||
45 child_process_id == kInvalidChildProcessId);
46 g_unique_child_process_id = child_process_id;
23 } 47 }
24 48
25 std::string MemoryAllocatorDumpGuid::ToString() const { 49 std::string MemoryAllocatorDumpGuid::ToString() const {
26 return StringPrintf("%" PRIx64, guid_); 50 return StringPrintf("%" PRIx64, guid_);
27 } 51 }
28 52
29 } // namespace trace_event 53 } // namespace trace_event
30 } // namespace base 54 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698