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 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ |
6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 namespace trace_event { | 14 namespace trace_event { |
15 | 15 |
16 class BASE_EXPORT MemoryAllocatorDumpGuid { | 16 class BASE_EXPORT MemoryAllocatorDumpGuid { |
17 public: | 17 public: |
| 18 static const int kInvalidChildProcessId = -1; |
| 19 |
18 MemoryAllocatorDumpGuid(); | 20 MemoryAllocatorDumpGuid(); |
19 explicit MemoryAllocatorDumpGuid(uint64 guid); | 21 explicit MemoryAllocatorDumpGuid(uint64 guid); |
20 | 22 |
21 // Utility ctor to hash a GUID if the caller prefers a string. The caller | 23 // Utility ctor to hash a GUID if the caller prefers a string. The caller |
22 // still has to ensure that |guid_str| is unique, per snapshot, within the | 24 // can insert "$$" in the string and it will be replaced by the unique child |
23 // global scope of all the traced processes. | 25 // process id for creating cross-process unique guid. Otherwise the caller |
| 26 // has to ensure that |guid_str| is unique, per snapshot, within the global |
| 27 // scope of all the traced processes. |
| 28 // NOTE: In single process mode or when tracing is not enabled the "$$" does |
| 29 // not get replaced and the caller has to set the id. |
24 explicit MemoryAllocatorDumpGuid(const std::string& guid_str); | 30 explicit MemoryAllocatorDumpGuid(const std::string& guid_str); |
25 | 31 |
| 32 // Sets the unique id of the child process for creating cross process unique |
| 33 // guids. Pass kInvalidChildProcessId for invalidating the id. |
| 34 static void SetUniqueChildProcessId(int child_process_id); |
| 35 |
26 uint64 ToUint64() const { return guid_; } | 36 uint64 ToUint64() const { return guid_; } |
27 | 37 |
28 // Returns a (hex-encoded) string representation of the guid. | 38 // Returns a (hex-encoded) string representation of the guid. |
29 std::string ToString() const; | 39 std::string ToString() const; |
30 | 40 |
31 bool empty() const { return guid_ == 0u; } | 41 bool empty() const { return guid_ == 0u; } |
32 | 42 |
33 bool operator==(const MemoryAllocatorDumpGuid& other) const { | 43 bool operator==(const MemoryAllocatorDumpGuid& other) const { |
34 return guid_ == other.guid_; | 44 return guid_ == other.guid_; |
35 } | 45 } |
36 | 46 |
37 bool operator!=(const MemoryAllocatorDumpGuid& other) const { | 47 bool operator!=(const MemoryAllocatorDumpGuid& other) const { |
38 return !(*this == other); | 48 return !(*this == other); |
39 } | 49 } |
40 | 50 |
41 private: | 51 private: |
42 uint64 guid_; | 52 uint64 guid_; |
43 | 53 |
44 // Deliberately copy-able. | 54 // Deliberately copy-able. |
45 }; | 55 }; |
46 | 56 |
47 } // namespace trace_event | 57 } // namespace trace_event |
48 } // namespace base | 58 } // namespace base |
49 | 59 |
50 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ | 60 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ |
OLD | NEW |