tools/profiler/shared-libraries.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d4acb12c2cfa
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef SHARED_LIBRARIES_H_
8 #define SHARED_LIBRARIES_H_
9
10 #ifndef MOZ_ENABLE_PROFILER_SPS
11 #error This header does not have a useful implementation on your platform!
12 #endif
13
14 #include <algorithm>
15 #include <vector>
16 #include <string>
17 #include <stdlib.h>
18 #include <stdint.h>
19 #include <nsID.h>
20
21 class SharedLibrary {
22 public:
23
24 SharedLibrary(uintptr_t aStart,
25 uintptr_t aEnd,
26 uintptr_t aOffset,
27 const std::string& aBreakpadId,
28 const std::string& aName)
29 : mStart(aStart)
30 , mEnd(aEnd)
31 , mOffset(aOffset)
32 , mBreakpadId(aBreakpadId)
33 , mName(aName)
34 {}
35
36 SharedLibrary(const SharedLibrary& aEntry)
37 : mStart(aEntry.mStart)
38 , mEnd(aEntry.mEnd)
39 , mOffset(aEntry.mOffset)
40 , mBreakpadId(aEntry.mBreakpadId)
41 , mName(aEntry.mName)
42 {}
43
44 SharedLibrary& operator=(const SharedLibrary& aEntry)
45 {
46 // Gracefully handle self assignment
47 if (this == &aEntry) return *this;
48
49 mStart = aEntry.mStart;
50 mEnd = aEntry.mEnd;
51 mOffset = aEntry.mOffset;
52 mBreakpadId = aEntry.mBreakpadId;
53 mName = aEntry.mName;
54 return *this;
55 }
56
57 bool operator==(const SharedLibrary& other) const
58 {
59 return (mStart == other.mStart) &&
60 (mEnd == other.mEnd) &&
61 (mOffset == other.mOffset) &&
62 (mName == other.mName) &&
63 (mBreakpadId == other.mBreakpadId);
64 }
65
66 uintptr_t GetStart() const { return mStart; }
67 uintptr_t GetEnd() const { return mEnd; }
68 uintptr_t GetOffset() const { return mOffset; }
69 const std::string &GetBreakpadId() const { return mBreakpadId; }
70 const std::string &GetName() const { return mName; }
71
72 private:
73 SharedLibrary() {}
74
75 uintptr_t mStart;
76 uintptr_t mEnd;
77 uintptr_t mOffset;
78 std::string mBreakpadId;
79 std::string mName;
80 };
81
82 static bool
83 CompareAddresses(const SharedLibrary& first, const SharedLibrary& second)
84 {
85 return first.GetStart() < second.GetStart();
86 }
87
88 class SharedLibraryInfo {
89 public:
90 static SharedLibraryInfo GetInfoForSelf();
91 SharedLibraryInfo() {}
92
93 void AddSharedLibrary(SharedLibrary entry)
94 {
95 mEntries.push_back(entry);
96 }
97
98 const SharedLibrary& GetEntry(size_t i) const
99 {
100 return mEntries[i];
101 }
102
103 // Removes items in the range [first, last)
104 // i.e. element at the "last" index is not removed
105 void RemoveEntries(size_t first, size_t last)
106 {
107 mEntries.erase(mEntries.begin() + first, mEntries.begin() + last);
108 }
109
110 bool Contains(const SharedLibrary& searchItem) const
111 {
112 return (mEntries.end() !=
113 std::find(mEntries.begin(), mEntries.end(), searchItem));
114 }
115
116 size_t GetSize() const
117 {
118 return mEntries.size();
119 }
120
121 void SortByAddress()
122 {
123 std::sort(mEntries.begin(), mEntries.end(), CompareAddresses);
124 }
125
126 void Clear()
127 {
128 mEntries.clear();
129 }
130
131 private:
132 std::vector<SharedLibrary> mEntries;
133 };
134
135 #endif

mercurial