/src/mozilla-central/toolkit/components/telemetry/other/KeyedStackCapturer.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; 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/. */ |
5 | | |
6 | | #ifndef KeyedStackCapturer_h__ |
7 | | #define KeyedStackCapturer_h__ |
8 | | |
9 | | #include "mozilla/Telemetry.h" |
10 | | #include "nsString.h" |
11 | | #include "nsClassHashtable.h" |
12 | | #include "mozilla/Mutex.h" |
13 | | #include "CombinedStacks.h" |
14 | | |
15 | | struct JSContext; |
16 | | |
17 | | namespace mozilla { |
18 | | namespace Telemetry { |
19 | | |
20 | | /** |
21 | | * Allows taking a snapshot of a call stack on demand. Captured stacks are |
22 | | * indexed by a string key in a hash table. The stack is only captured Once |
23 | | * for each key. Consequent captures with the same key result in incrementing |
24 | | * capture counter without re-capturing the stack. |
25 | | */ |
26 | | class KeyedStackCapturer |
27 | | { |
28 | | public: |
29 | | KeyedStackCapturer() |
30 | | : mStackCapturerMutex("Telemetry::StackCapturerMutex") |
31 | 3 | {} |
32 | | |
33 | | /** |
34 | | * Captures a stack for the given key. |
35 | | */ |
36 | | void Capture(const nsACString& aKey); |
37 | | |
38 | | /** |
39 | | * Transforms captured stacks into a JS object. |
40 | | */ |
41 | | NS_IMETHODIMP ReflectCapturedStacks( |
42 | | JSContext *cx, JS::MutableHandle<JS::Value> ret); |
43 | | |
44 | | /** |
45 | | * Resets captured stacks and the information related to them. |
46 | | */ |
47 | | void Clear(); |
48 | | |
49 | | size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
50 | | |
51 | | private: |
52 | | /** |
53 | | * Describes how often a stack was captured. |
54 | | */ |
55 | | struct StackFrequencyInfo { |
56 | | // A number of times the stack was captured. |
57 | | uint32_t mCount; |
58 | | // Index of the stack inside stacks array. |
59 | | uint32_t mIndex; |
60 | | |
61 | | StackFrequencyInfo(uint32_t aCount, uint32_t aIndex) |
62 | | : mCount(aCount) |
63 | | , mIndex(aIndex) |
64 | 0 | {} |
65 | | }; |
66 | | |
67 | | typedef nsClassHashtable<nsCStringHashKey, StackFrequencyInfo> FrequencyInfoMapType; |
68 | | |
69 | | FrequencyInfoMapType mStackInfos; |
70 | | CombinedStacks mStacks; |
71 | | Mutex mStackCapturerMutex; |
72 | | }; |
73 | | |
74 | | } // namespace Telemetry |
75 | | } // namespace mozilla |
76 | | |
77 | | #endif // KeyedStackCapturer_h__ |