michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * A mechanism for interacting with operating system-provided michael@0: * debugging/profiling tools such as Microsoft EWT/Windows Performance Toolkit. michael@0: */ michael@0: michael@0: #ifndef mozilla_perfprobe_h michael@0: #define mozilla_perfprobe_h michael@0: michael@0: #if !defined(XP_WIN) michael@0: #error "For the moment, perfprobe.h is defined only for Windows platforms" michael@0: #endif michael@0: michael@0: #include "nsError.h" michael@0: #include "nsString.h" michael@0: #include "prlog.h" michael@0: #include "nsTArray.h" michael@0: #include "nsAutoPtr.h" michael@0: #include michael@0: #undef GetStartupInfo //Prevent Windows from polluting global namespace michael@0: #include michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace probes { michael@0: michael@0: class ProbeManager; michael@0: michael@0: /** michael@0: * A data structure supporting a trigger operation that can be used to michael@0: * send information to the operating system. michael@0: */ michael@0: michael@0: class Probe michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(Probe) michael@0: michael@0: /** michael@0: * Trigger the event. michael@0: * michael@0: * Note: Can be called from any thread. michael@0: */ michael@0: nsresult Trigger(); michael@0: ~Probe() {}; michael@0: michael@0: protected: michael@0: Probe(const nsCID &aGUID, michael@0: const nsACString &aName, michael@0: ProbeManager *aManager); michael@0: friend class ProbeManager; michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * The system GUID associated to this probe. See the documentation michael@0: * of |ProbeManager::Make| for more details. michael@0: */ michael@0: const GUID mGUID; michael@0: michael@0: /** michael@0: * The name of this probe. See the documentation michael@0: * of |ProbeManager::Make| for more details. michael@0: */ michael@0: const nsCString mName; michael@0: michael@0: /** michael@0: * The ProbeManager managing this probe. michael@0: * michael@0: * Note: This is a weak reference to avoid a useless cycle. michael@0: */ michael@0: class ProbeManager *mManager; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * A manager for a group of probes. michael@0: * michael@0: * You can have several managers in one application, provided that they all michael@0: * have distinct IDs and names. However, having more than 2 is considered a bad michael@0: * practice. michael@0: */ michael@0: class ProbeManager michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(ProbeManager) michael@0: michael@0: /** michael@0: * Create a new probe manager. michael@0: * michael@0: * This constructor should be called from the main thread. michael@0: * michael@0: * @param uid The unique ID of the probe. Under Windows, this unique michael@0: * ID must have been previously registered using an external tool. michael@0: * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx michael@0: * @param name A name for the probe. Currently used only for logging purposes. michael@0: * In the future, may be attached to the data sent to the operating system. michael@0: * michael@0: * Note: If two ProbeManagers are constructed with the same uid and/or name, michael@0: * behavior is unspecified. michael@0: */ michael@0: ProbeManager(const nsCID &applicationUID, michael@0: const nsACString &applicationName); michael@0: michael@0: /** michael@0: * Acquire a probe. michael@0: * michael@0: * Note: Only probes acquired before the call to SetReady are taken into michael@0: * account michael@0: * Note: Can be called only from the main thread. michael@0: * michael@0: * @param eventUID The unique ID of the probe. Under Windows, this unique michael@0: * ID must have been previously registered using an external tool. michael@0: * See MyCategory on http://msdn.microsoft.com/en-us/library/aa364100.aspx michael@0: * @param eventMame A name for the probe. Currently used only for logging michael@0: * purposes. In the michael@0: * future, may be attached to the data sent to the operating system. michael@0: * @return Either |null| in case of error or a valid |Probe*|. michael@0: * michael@0: * Note: If this method is called twice with the same uid and/or name, michael@0: * behavior is undefined. michael@0: */ michael@0: already_AddRefed GetProbe(const nsCID &eventUID, michael@0: const nsACString &eventName); michael@0: michael@0: /** michael@0: * Start/stop the measuring session. michael@0: * michael@0: * This method should be called from the main thread. michael@0: * michael@0: * Note that starting an already started probe manager has no effect, michael@0: * nor does stopping an already stopped probe manager. michael@0: */ michael@0: nsresult StartSession(); michael@0: nsresult StopSession(); michael@0: michael@0: /** michael@0: * @return true If measures are currently on, i.e. if triggering probes is any michael@0: * is useful. You do not have to check this before triggering a probe, unless michael@0: * this can avoid complex computations. michael@0: */ michael@0: bool IsActive(); michael@0: michael@0: ~ProbeManager(); michael@0: michael@0: protected: michael@0: nsresult StartSession(nsTArray > &probes); michael@0: nsresult Init(const nsCID &applicationUID, const nsACString &applicationName); michael@0: michael@0: protected: michael@0: /** michael@0: * `true` if a session is in activity, `false` otherwise. michael@0: */ michael@0: bool mIsActive; michael@0: michael@0: /** michael@0: * The UID of this manager. michael@0: * See documentation above for registration steps that you michael@0: * may have to take. michael@0: */ michael@0: nsCID mApplicationUID; michael@0: michael@0: /** michael@0: * The name of the application. michael@0: */ michael@0: nsCString mApplicationName; michael@0: michael@0: /** michael@0: * All the probes that have been created for this manager. michael@0: */ michael@0: nsTArray > mAllProbes; michael@0: michael@0: /** michael@0: * Handle used for triggering events michael@0: */ michael@0: TRACEHANDLE mSessionHandle; michael@0: michael@0: /** michael@0: * Handle used for registration/unregistration michael@0: */ michael@0: TRACEHANDLE mRegistrationHandle; michael@0: michael@0: /** michael@0: * `true` if initialization has been performed, `false` until then. michael@0: */ michael@0: bool mInitialized; michael@0: michael@0: friend class Probe;//Needs to access |mSessionHandle| michael@0: friend ULONG WINAPI ControlCallback( michael@0: WMIDPREQUESTCODE RequestCode, michael@0: PVOID Context, michael@0: ULONG *Reserved, michael@0: PVOID Buffer michael@0: );//Sets |mSessionHandle| michael@0: }; michael@0: } michael@0: } michael@0: michael@0: #endif //mozilla_perfprobe_h