1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef CombinedStacks_h__
7 #define CombinedStacks_h__
11 #include "ipc/IPCMessageUtils.h"
12 #include "ProcessedStack.h"
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.
24 class CombinedStacks
{
26 explicit CombinedStacks();
27 explicit CombinedStacks(size_t aMaxStacksCount
);
29 CombinedStacks(CombinedStacks
&&) = default;
30 CombinedStacks
& operator=(CombinedStacks
&&) = default;
32 void Swap(CombinedStacks
& aOther
);
34 typedef std::vector
<Telemetry::ProcessedStack::Frame
> Stack
;
35 const Telemetry::ProcessedStack::Module
& GetModule(unsigned aIndex
) const;
36 size_t GetModuleCount() const;
37 const Stack
& GetStack(unsigned aIndex
) const;
38 size_t AddStack(const Telemetry::ProcessedStack
& aStack
);
39 void AddStacks(const CombinedStacks
& aStacks
);
40 size_t GetStackCount() const;
41 size_t SizeOfExcludingThis() const;
42 void RemoveStack(unsigned aIndex
);
43 size_t GetMaxStacksCount() const;
45 /** Clears the contents of vectors and resets the index. */
49 std::vector
<Telemetry::ProcessedStack::Module
> mModules
;
50 // A circular buffer to hold the stacks.
51 std::vector
<Stack
> mStacks
;
52 // The index of the next buffer element to write to in mStacks.
54 // The maximum number of stacks to keep in the CombinedStacks object.
55 size_t mMaxStacksCount
;
58 size_t aStackIndex
, const ProcessedStack::Frame
& aFrame
,
59 const std::function
<const ProcessedStack::Module
&(int)>& aModuleGetter
);
61 friend struct ::IPC::ParamTraits
<CombinedStacks
>;
65 * Creates a JSON representation of given combined stacks object.
67 JSObject
* CreateJSStackObject(JSContext
* cx
, const CombinedStacks
& stacks
);
69 } // namespace Telemetry
70 } // namespace mozilla
75 struct ParamTraits
<mozilla::Telemetry::CombinedStacks
> {
76 typedef mozilla::Telemetry::CombinedStacks paramType
;
78 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
) {
79 WriteParam(aWriter
, aParam
.mModules
);
80 WriteParam(aWriter
, aParam
.mStacks
);
81 WriteParam(aWriter
, aParam
.mNextIndex
);
82 WriteParam(aWriter
, aParam
.mMaxStacksCount
);
85 static bool Read(MessageReader
* aReader
, paramType
* aResult
) {
86 if (!ReadParam(aReader
, &aResult
->mModules
)) {
90 if (!ReadParam(aReader
, &aResult
->mStacks
)) {
94 if (!ReadParam(aReader
, &aResult
->mNextIndex
)) {
98 if (!ReadParam(aReader
, &aResult
->mMaxStacksCount
)) {
108 #endif // CombinedStacks_h__