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 3 // found in the LICENSE file. 4 5 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ 6 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ 7 8 #include <stdint.h> 9 10 #include <string> 11 12 #include "base/base_export.h" 13 14 namespace base { 15 namespace trace_event { 16 17 class BASE_EXPORT MemoryAllocatorDumpGuid { 18 public: 19 MemoryAllocatorDumpGuid(); 20 explicit MemoryAllocatorDumpGuid(uint64_t guid); 21 22 // Utility ctor to hash a GUID if the caller prefers a string. The caller 23 // still has to ensure that |guid_str| is unique, per snapshot, within the 24 // global scope of all the traced processes. 25 explicit MemoryAllocatorDumpGuid(const std::string& guid_str); 26 ToUint64()27 uint64_t ToUint64() const { return guid_; } 28 29 // Returns a (hex-encoded) string representation of the guid. 30 std::string ToString() const; 31 empty()32 bool empty() const { return guid_ == 0u; } 33 34 bool operator==(const MemoryAllocatorDumpGuid& other) const { 35 return guid_ == other.guid_; 36 } 37 38 bool operator!=(const MemoryAllocatorDumpGuid& other) const { 39 return !(*this == other); 40 } 41 42 bool operator<(const MemoryAllocatorDumpGuid& other) const { 43 return guid_ < other.guid_; 44 } 45 46 private: 47 uint64_t guid_; 48 49 // Deliberately copy-able. 50 }; 51 52 } // namespace trace_event 53 } // namespace base 54 55 #endif // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_GUID_H_ 56