Bug 796834 - B2G RIL: Setup data call returns fail during radio power changed. r...
[gecko.git] / xpcom / build / perfprobe.h
blob53ea5428fa9e089e3af2d782734d74345947d509
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/. */
6 /**
7 * A mechanism for interacting with operating system-provided
8 * debugging/profiling tools such as Microsoft EWT/Windows Performance Toolkit.
9 */
11 #ifndef mozilla_perfprobe_h
12 #define mozilla_perfprobe_h
14 #if !defined(XP_WIN)
15 #error "For the moment, perfprobe.h is defined only for Windows platforms"
16 #endif
18 #include "nsError.h"
19 #include "nsStringGlue.h"
20 #include "prlog.h"
21 #include "nsTArray.h"
22 #include "nsAutoPtr.h"
23 #include <windows.h>
24 #undef GetStartupInfo //Prevent Windows from polluting global namespace
25 #include <wmistr.h>
26 #include <evntrace.h>
28 namespace mozilla {
29 namespace probes {
31 class ProbeManager;
33 /**
34 * A data structure supporting a trigger operation that can be used to
35 * send information to the operating system.
38 class Probe
40 public:
41 NS_INLINE_DECL_REFCOUNTING(Probe)
43 /**
44 * Trigger the event.
46 * Note: Can be called from any thread.
48 nsresult Trigger();
49 ~Probe() {};
51 protected:
52 Probe(const nsCID &aGUID,
53 const nsACString &aName,
54 ProbeManager *aManager);
55 friend class ProbeManager;
57 protected:
59 /**
60 * The system GUID associated to this probe. See the documentation
61 * of |ProbeManager::Make| for more details.
63 const GUID mGUID;
65 /**
66 * The name of this probe. See the documentation
67 * of |ProbeManager::Make| for more details.
69 const nsCString mName;
71 /**
72 * The ProbeManager managing this probe.
74 * Note: This is a weak reference to avoid a useless cycle.
76 class ProbeManager *mManager;
80 /**
81 * A manager for a group of probes.
83 * You can have several managers in one application, provided that they all
84 * have distinct IDs and names. However, having more than 2 is considered a bad
85 * practice.
87 class ProbeManager
89 public:
90 NS_INLINE_DECL_REFCOUNTING(ProbeManager)
92 /**
93 * Create a new probe manager.
95 * This constructor should be called from the main thread.
97 * @param uid The unique ID of the probe. Under Windows, this unique
98 * ID must have been previously registered using an external tool.
99 * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx
100 * @param name A name for the probe. Currently used only for logging purposes.
101 * In the future, may be attached to the data sent to the operating system.
103 * Note: If two ProbeManagers are constructed with the same uid and/or name,
104 * behavior is unspecified.
106 ProbeManager(const nsCID &applicationUID,
107 const nsACString &applicationName);
110 * Acquire a probe.
112 * Note: Only probes acquired before the call to SetReady are taken into
113 * account
114 * Note: Can be called only from the main thread.
116 * @param eventUID The unique ID of the probe. Under Windows, this unique
117 * ID must have been previously registered using an external tool.
118 * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx
119 * @param eventMame A name for the probe. Currently used only for logging
120 * purposes. In the
121 * future, may be attached to the data sent to the operating system.
122 * @return Either |null| in case of error or a valid |Probe*|.
124 * Note: If this method is called twice with the same uid and/or name,
125 * behavior is undefined.
127 already_AddRefed<Probe> GetProbe(const nsCID &eventUID,
128 const nsACString &eventName);
131 * Start/stop the measuring session.
133 * This method should be called from the main thread.
135 * Note that starting an already started probe manager has no effect,
136 * nor does stopping an already stopped probe manager.
138 nsresult StartSession();
139 nsresult StopSession();
142 * @return true If measures are currently on, i.e. if triggering probes is any
143 * is useful. You do not have to check this before triggering a probe, unless
144 * this can avoid complex computations.
146 bool IsActive();
148 ~ProbeManager();
150 protected:
151 nsresult StartSession(nsTArray<nsRefPtr<Probe> > &probes);
152 nsresult Init(const nsCID &applicationUID, const nsACString &applicationName);
154 protected:
156 * `true` if a session is in activity, `false` otherwise.
158 bool mIsActive;
161 * The UID of this manager.
162 * See documentation above for registration steps that you
163 * may have to take.
165 nsCID mApplicationUID;
168 * The name of the application.
170 nsCString mApplicationName;
173 * All the probes that have been created for this manager.
175 nsTArray<nsRefPtr<Probe> > mAllProbes;
178 * Handle used for triggering events
180 TRACEHANDLE mSessionHandle;
183 * Handle used for registration/unregistration
185 TRACEHANDLE mRegistrationHandle;
188 * `true` if initialization has been performed, `false` until then.
190 bool mInitialized;
192 friend class Probe;//Needs to access |mSessionHandle|
193 friend ULONG WINAPI ControlCallback(
194 WMIDPREQUESTCODE RequestCode,
195 PVOID Context,
196 ULONG *Reserved,
197 PVOID Buffer
198 );//Sets |mSessionHandle|
203 #endif //mozilla_perfprobe_h