Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4829)

Unified Diff: chrome/profiling/address.h

Issue 2943733002: Add out-of-process memory logging stream parsing. (Closed)
Patch Set: Format Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/profiling/address.h
diff --git a/chrome/profiling/address.h b/chrome/profiling/address.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb0166640182ac29cee8ad6b8d923b792a981ad6
--- /dev/null
+++ b/chrome/profiling/address.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef CHROME_PROFILING_ADDRESS_H_
+#define CHROME_PROFILING_ADDRESS_H_
+
+#include <stdint.h>
+
+#include <functional>
+#include <iosfwd>
+
+namespace profiling {
+
+// Wrapper around an address in the instrumented process. This wrapper should
+// be a zero-overhead abstraction around a 64-bit integer (so pass by value)
+// that prevents getting confused between addresses in the local process and
+// ones in the instrumented process.
+struct Address {
+ Address() : value(0) {}
+ explicit Address(uint64_t v) : value(v) {}
+
+ uint64_t value;
+
+ bool operator<(Address other) const { return value < other.value; }
+ bool operator<=(Address other) const { return value <= other.value; }
+ bool operator>(Address other) const { return value > other.value; }
+ bool operator>=(Address other) const { return value >= other.value; }
+
+ bool operator==(Address other) const { return value == other.value; }
+ bool operator!=(Address other) const { return value != other.value; }
+
+ Address operator+(int64_t delta) const { return Address(value + delta); }
+ Address operator+=(int64_t delta) {
+ value += delta;
+ return *this;
+ }
+
+ Address operator-(int64_t delta) const { return Address(value - delta); }
+ Address operator-=(int64_t delta) {
+ value -= delta;
+ return *this;
+ }
+
+ int64_t operator-(Address a) const { return value - a.value; }
+};
+
+} // namespace profiling
+
+namespace std {
+
+template <>
+struct hash<profiling::Address> {
+ typedef profiling::Address argument_type;
+ typedef std::size_t result_type;
+ result_type operator()(argument_type a) const {
+ return static_cast<size_t>(a.value);
+ }
+};
+
+} // namespace std
+
+std::ostream& operator<<(std::ostream& out, profiling::Address a);
+
+#endif // CHROME_PROFILING_ADDRESS_H_

Powered by Google App Engine
This is Rietveld 408576698