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.
5 #include "base/trace_event/memory_allocator_dump_guid.h"
7 #include "base/format_macros.h"
9 #include "base/strings/stringprintf.h"
12 namespace trace_event
{
15 uint64
HashString(const std::string
& str
) {
16 uint64 hash
[(kSHA1Length
+ sizeof(uint64
) - 1) / sizeof(uint64
)] = { 0 };
17 SHA1HashBytes(reinterpret_cast<const unsigned char*>(str
.data()), str
.size(),
18 reinterpret_cast<unsigned char*>(hash
));
23 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(uint64 guid
) : guid_(guid
) {
26 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid()
27 : MemoryAllocatorDumpGuid(0u) {
30 MemoryAllocatorDumpGuid::MemoryAllocatorDumpGuid(const std::string
& guid_str
)
31 : MemoryAllocatorDumpGuid(HashString(guid_str
)) {
34 std::string
MemoryAllocatorDumpGuid::ToString() const {
35 return StringPrintf("%" PRIx64
, guid_
);
38 } // namespace trace_event