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 #include "base/trace_event/memory_allocator_dump_guid.h" 6 7 #include "base/format_macros.h" 8 #include "base/sha1.h" 9 #include "base/strings/stringprintf.h" 10 11 namespace base { 12 namespace trace_event { 13 14 namespace { 15 HashString(const std::string & str)16uint64_t HashString(const std::string& str) { 17 uint64_t hash[(kSHA1Length + sizeof(uint64_t) - 1) / sizeof(uint64_t)] = {0}; 18 SHA1HashBytes(reinterpret_cast<const unsigned char*>(str.data()), str.size(), 19 reinterpret_cast<unsigned char*>(hash)); 20 return hash[0]; 21 } 22 23 } // namespace 24 MemoryAllocatorDumpGuid(uint64_t guid)25MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64_t guid) : guid_(guid) {} 26 MemoryAllocatorDumpGuid()27MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid() 28 : MemoryAllocatorDumpGuid(0u) { 29 } 30 MemoryAllocatorDumpGuid(const std::string & guid_str)31MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string& guid_str) 32 : MemoryAllocatorDumpGuid(HashString(guid_str)) { 33 } 34 ToString() const35std::string MemoryAllocatorDumpGuid::ToString() const { 36 return StringPrintf("%" PRIx64, guid_); 37 } 38 39 } // namespace trace_event 40 } // namespace base 41