forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbacktrace.cc
48 lines (33 loc) · 1.25 KB
/
backtrace.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/profiling/backtrace.h"
#include <string.h>
#include <algorithm>
#include "base/hash.h"
#include "chrome/profiling/backtrace_storage.h"
namespace profiling {
namespace {
// TODO(ajwong) replace with a fingerprint capable hash.
size_t ComputeHash(const std::vector<Address>& addrs) {
if (addrs.empty())
return 0;
// Assume Address is a POD containing only the address with no padding.
return base::Hash(addrs.data(), addrs.size() * sizeof(Address));
}
} // namespace
Backtrace::Backtrace(std::vector<Address>&& a)
: addrs_(std::move(a)), fingerprint_(ComputeHash(addrs_)) {}
Backtrace::Backtrace(Backtrace&& other) noexcept = default;
Backtrace::~Backtrace() {}
Backtrace& Backtrace::operator=(Backtrace&& other) = default;
bool Backtrace::operator==(const Backtrace& other) const {
if (addrs_.size() != other.addrs_.size())
return false;
return memcmp(addrs_.data(), other.addrs_.data(),
addrs_.size() * sizeof(Address)) == 0;
}
bool Backtrace::operator!=(const Backtrace& other) const {
return !operator==(other);
}
} // namespace profiling