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