1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/telemetry/ProcessedStack.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef ProcessedStack_h__ 1.10 +#define ProcessedStack_h__ 1.11 + 1.12 +#include <string> 1.13 +#include <vector> 1.14 + 1.15 +namespace mozilla { 1.16 +namespace Telemetry { 1.17 + 1.18 +// This class represents a stack trace and the modules referenced in that trace. 1.19 +// It is designed to be easy to read and write to disk or network and doesn't 1.20 +// include any logic on how to collect or read the information it stores. 1.21 +class ProcessedStack 1.22 +{ 1.23 +public: 1.24 + ProcessedStack(); 1.25 + size_t GetStackSize() const; 1.26 + size_t GetNumModules() const; 1.27 + 1.28 + struct Frame 1.29 + { 1.30 + // The offset of this program counter in its module or an absolute pc. 1.31 + uintptr_t mOffset; 1.32 + // The index to pass to GetModule to get the module this program counter 1.33 + // was in. 1.34 + uint16_t mModIndex; 1.35 + }; 1.36 + struct Module 1.37 + { 1.38 + // The file name, /foo/bar/libxul.so for example. 1.39 + std::string mName; 1.40 + std::string mBreakpadId; 1.41 + 1.42 + bool operator==(const Module& other) const; 1.43 + }; 1.44 + 1.45 + const Frame &GetFrame(unsigned aIndex) const; 1.46 + void AddFrame(const Frame& aFrame); 1.47 + const Module &GetModule(unsigned aIndex) const; 1.48 + void AddModule(const Module& aFrame); 1.49 + 1.50 + void Clear(); 1.51 + 1.52 +private: 1.53 + std::vector<Module> mModules; 1.54 + std::vector<Frame> mStack; 1.55 +}; 1.56 + 1.57 +// Get the current list of loaded modules, filter and pair it to the provided 1.58 +// stack. We let the caller collect the stack since different callers have 1.59 +// different needs (current thread X main thread, stopping the thread, etc). 1.60 +ProcessedStack 1.61 +GetStackAndModules(const std::vector<uintptr_t> &aPCs); 1.62 + 1.63 +} // namespace Telemetry 1.64 +} // namespace mozilla 1.65 +#endif // ProcessedStack_h__