1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
8 * A mechanism for interacting with operating system-provided
9 * debugging/profiling tools such as Microsoft EWT/Windows Performance Toolkit.
12 #ifndef mozilla_perfprobe_h
13 #define mozilla_perfprobe_h
16 # error "For the moment, perfprobe.h is defined only for Windows platforms"
21 #include "mozilla/Logging.h"
24 #undef GetStartupInfo // Prevent Windows from polluting global namespace
34 * A data structure supporting a trigger operation that can be used to
35 * send information to the operating system.
40 NS_INLINE_DECL_REFCOUNTING(Probe
)
45 * Note: Can be called from any thread.
52 Probe(const nsCID
& aGUID
, const nsACString
& aName
, ProbeManager
* aManager
);
53 friend class ProbeManager
;
57 * The system GUID associated to this probe. See the documentation
58 * of |ProbeManager::Make| for more details.
63 * The name of this probe. See the documentation
64 * of |ProbeManager::Make| for more details.
66 const nsCString mName
;
69 * The ProbeManager managing this probe.
71 * Note: This is a weak reference to avoid a useless cycle.
73 class ProbeManager
* mManager
;
77 * A manager for a group of probes.
79 * You can have several managers in one application, provided that they all
80 * have distinct IDs and names. However, having more than 2 is considered a bad
85 NS_INLINE_DECL_REFCOUNTING(ProbeManager
)
88 * Create a new probe manager.
90 * This constructor should be called from the main thread.
92 * @param aApplicationUID The unique ID of the probe. Under Windows, this
93 * unique ID must have been previously registered using an external tool.
94 * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx
95 * @param aApplicationName A name for the probe. Currently used only for
96 * logging purposes. In the future, may be attached to the data sent to the
99 * Note: If two ProbeManagers are constructed with the same uid and/or name,
100 * behavior is unspecified.
102 ProbeManager(const nsCID
& aApplicationUID
,
103 const nsACString
& aApplicationName
);
108 * Note: Only probes acquired before the call to SetReady are taken into
110 * Note: Can be called only from the main thread.
112 * @param aEventUID The unique ID of the probe. Under Windows, this unique
113 * ID must have been previously registered using an external tool.
114 * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx
115 * @param aEventName A name for the probe. Currently used only for logging
117 * future, may be attached to the data sent to the operating system.
118 * @return Either |null| in case of error or a valid |Probe*|.
120 * Note: If this method is called twice with the same uid and/or name,
121 * behavior is undefined.
123 already_AddRefed
<Probe
> GetProbe(const nsCID
& aEventUID
,
124 const nsACString
& aEventName
);
127 * Start/stop the measuring session.
129 * This method should be called from the main thread.
131 * Note that starting an already started probe manager has no effect,
132 * nor does stopping an already stopped probe manager.
134 nsresult
StartSession();
135 nsresult
StopSession();
138 * @return true If measures are currently on, i.e. if triggering probes is any
139 * is useful. You do not have to check this before triggering a probe, unless
140 * this can avoid complex computations.
147 nsresult
StartSession(nsTArray
<RefPtr
<Probe
>>& aProbes
);
148 nsresult
Init(const nsCID
& aApplicationUID
,
149 const nsACString
& aApplicationName
);
153 * `true` if a session is in activity, `false` otherwise.
158 * The UID of this manager.
159 * See documentation above for registration steps that you
162 nsCID mApplicationUID
;
165 * The name of the application.
167 nsCString mApplicationName
;
170 * All the probes that have been created for this manager.
172 nsTArray
<RefPtr
<Probe
>> mAllProbes
;
175 * Handle used for triggering events
177 TRACEHANDLE mSessionHandle
;
180 * Handle used for registration/unregistration
182 TRACEHANDLE mRegistrationHandle
;
185 * `true` if initialization has been performed, `false` until then.
189 friend class Probe
; // Needs to access |mSessionHandle|
190 friend ULONG WINAPI
ControlCallback(WMIDPREQUESTCODE aRequestCode
,
191 PVOID aContext
, ULONG
* aReserved
,
192 PVOID aBuffer
); // Sets |mSessionHandle|
195 } // namespace probes
196 } // namespace mozilla
198 #endif // mozilla_perfprobe_h