1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- 2 */ 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 CombinedStacks_h__ 8 #define CombinedStacks_h__ 9 10 #include <vector> 11 12 #include "ProcessedStack.h" 13 14 class JSObject; 15 struct JSContext; 16 17 namespace mozilla { 18 namespace Telemetry { 19 20 /** 21 * This class is conceptually a list of ProcessedStack objects, but it 22 * represents them more efficiently by keeping a single global list of modules. 23 */ 24 class CombinedStacks { 25 public: 26 explicit CombinedStacks(); 27 explicit CombinedStacks(size_t aMaxStacksCount); 28 29 typedef std::vector<Telemetry::ProcessedStack::Frame> Stack; 30 const Telemetry::ProcessedStack::Module& GetModule(unsigned aIndex) const; 31 size_t GetModuleCount() const; 32 const Stack& GetStack(unsigned aIndex) const; 33 size_t AddStack(const Telemetry::ProcessedStack& aStack); 34 size_t GetStackCount() const; 35 size_t SizeOfExcludingThis() const; 36 37 #if defined(MOZ_GECKO_PROFILER) 38 /** Clears the contents of vectors and resets the index. */ 39 void Clear(); 40 #endif 41 42 private: 43 std::vector<Telemetry::ProcessedStack::Module> mModules; 44 // A circular buffer to hold the stacks. 45 std::vector<Stack> mStacks; 46 // The index of the next buffer element to write to in mStacks. 47 size_t mNextIndex; 48 // The maximum number of stacks to keep in the CombinedStacks object. 49 size_t mMaxStacksCount; 50 }; 51 52 /** 53 * Creates a JSON representation of given combined stacks object. 54 */ 55 JSObject* CreateJSStackObject(JSContext* cx, const CombinedStacks& stacks); 56 57 } // namespace Telemetry 58 } // namespace mozilla 59 60 #endif // CombinedStacks_h__ 61