OLD | NEW |
---|---|
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; | |
Primiano Tucci (use gerrit)
2015/06/19 13:47:49
nit: g_ prefix
Add also a kInvalidChildProcessId =
ssid
2015/06/19 14:51:19
Done.
| |
15 | |
16 uint64 InsertChildIdAndHash(std::string guid_str) { | |
Primiano Tucci (use gerrit)
2015/06/19 13:47:49
nit: s/InsertChildIdAndHash/ExpandChildProcessIdAn
ssid
2015/06/19 14:51:19
Done.
| |
17 const char kReplaceChildIdStr[] = "$$"; | |
18 size_t pos = guid_str.find(kReplaceChildIdStr); | |
19 if (pos != std::string::npos) { | |
20 DCHECK_NE(unique_child_process_id, -1); | |
Primiano Tucci (use gerrit)
2015/06/19 13:47:49
use kInvalid... instead of -1
ssid
2015/06/19 14:51:19
Done.
| |
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; | |
Primiano Tucci (use gerrit)
2015/06/19 13:47:49
can you add a
DCHECK(child_process_id_ == kInval
ssid
2015/06/19 14:51:19
Done.
| |
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 |
OLD | NEW |