Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef ProcessedStack_h__ |
michael@0 | 7 | #define ProcessedStack_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include <string> |
michael@0 | 10 | #include <vector> |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace Telemetry { |
michael@0 | 14 | |
michael@0 | 15 | // This class represents a stack trace and the modules referenced in that trace. |
michael@0 | 16 | // It is designed to be easy to read and write to disk or network and doesn't |
michael@0 | 17 | // include any logic on how to collect or read the information it stores. |
michael@0 | 18 | class ProcessedStack |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | ProcessedStack(); |
michael@0 | 22 | size_t GetStackSize() const; |
michael@0 | 23 | size_t GetNumModules() const; |
michael@0 | 24 | |
michael@0 | 25 | struct Frame |
michael@0 | 26 | { |
michael@0 | 27 | // The offset of this program counter in its module or an absolute pc. |
michael@0 | 28 | uintptr_t mOffset; |
michael@0 | 29 | // The index to pass to GetModule to get the module this program counter |
michael@0 | 30 | // was in. |
michael@0 | 31 | uint16_t mModIndex; |
michael@0 | 32 | }; |
michael@0 | 33 | struct Module |
michael@0 | 34 | { |
michael@0 | 35 | // The file name, /foo/bar/libxul.so for example. |
michael@0 | 36 | std::string mName; |
michael@0 | 37 | std::string mBreakpadId; |
michael@0 | 38 | |
michael@0 | 39 | bool operator==(const Module& other) const; |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | const Frame &GetFrame(unsigned aIndex) const; |
michael@0 | 43 | void AddFrame(const Frame& aFrame); |
michael@0 | 44 | const Module &GetModule(unsigned aIndex) const; |
michael@0 | 45 | void AddModule(const Module& aFrame); |
michael@0 | 46 | |
michael@0 | 47 | void Clear(); |
michael@0 | 48 | |
michael@0 | 49 | private: |
michael@0 | 50 | std::vector<Module> mModules; |
michael@0 | 51 | std::vector<Frame> mStack; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | // Get the current list of loaded modules, filter and pair it to the provided |
michael@0 | 55 | // stack. We let the caller collect the stack since different callers have |
michael@0 | 56 | // different needs (current thread X main thread, stopping the thread, etc). |
michael@0 | 57 | ProcessedStack |
michael@0 | 58 | GetStackAndModules(const std::vector<uintptr_t> &aPCs); |
michael@0 | 59 | |
michael@0 | 60 | } // namespace Telemetry |
michael@0 | 61 | } // namespace mozilla |
michael@0 | 62 | #endif // ProcessedStack_h__ |