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

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: 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 {
13 namespace {
14 int unique_child_process_id = -1;
15
16 uint64 InsertChildIdAndHash(std::string guid_str) {
17 const char kReplaceChildIdStr[] = "$$";
picksi 2015/06/16 16:18:37 Random thought: Are we ever going to want to add o
ssid 2015/06/19 10:18:14 primiano@ WDYT?
18 size_t pos = guid_str.find(kReplaceChildIdStr);
picksi 2015/06/16 16:18:37 Does this code need to work fast? If so we could a
ssid 2015/06/19 10:18:14 hm, The string length is going to be small, so i d
19 if (pos != std::string::npos) {
20 DCHECK_NE(unique_child_process_id, -1);
21 guid_str.replace(pos, sizeof(kReplaceChildIdStr) - 1,
22 IntToString(unique_child_process_id));
23 }
24 return Hash(guid_str);
25 }
26 } // namespace
27
12 namespace trace_event { 28 namespace trace_event {
13 29
14 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64 guid) : guid_(guid) { 30 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64 guid) : guid_(guid) {
15 } 31 }
16 32
17 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid() 33 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid()
18 : MemoryAllocatorDumpGuid(0u) { 34 : MemoryAllocatorDumpGuid(0u) {
19 } 35 }
20 36
21 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str) 37 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str)
22 : MemoryAllocatorDumpGuid(Hash(guid_str)) { 38 : MemoryAllocatorDumpGuid(InsertChildIdAndHash(guid_str)) {
39 }
40
41 // static
42 void MemoryAllocatorDumpGuid::SetUniqueChildProcessId(int child_process_id) {
43 unique_child_process_id = child_process_id;
23 } 44 }
24 45
25 std::string MemoryAllocatorDumpGuid::ToString() const { 46 std::string MemoryAllocatorDumpGuid::ToString() const {
26 return StringPrintf("%" PRIx64, guid_); 47 return StringPrintf("%" PRIx64, guid_);
27 } 48 }
28 49
29 } // namespace trace_event 50 } // namespace trace_event
30 } // namespace base 51 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698