зеркало из https://github.com/mozilla/gecko-dev.git
bug 486793: add programmatic control of profiler to xpcom unit tests. r=bsmedberg
This commit is contained in:
Родитель
8ddb8a7fc5
Коммит
e8322d6258
|
@ -519,6 +519,12 @@ endif
|
|||
|
||||
include $(topsrcdir)/config/static-checking-config.mk
|
||||
|
||||
ifdef MOZ_SHARK
|
||||
OS_CFLAGS += -F/System/Library/PrivateFrameworks
|
||||
OS_CXXFLAGS += -F/System/Library/PrivateFrameworks
|
||||
OS_LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD
|
||||
endif # ifdef MOZ_SHARK
|
||||
|
||||
CFLAGS = $(OS_CFLAGS)
|
||||
CXXFLAGS = $(OS_CXXFLAGS)
|
||||
LDFLAGS = $(OS_LDFLAGS) $(MOZ_FIX_LINK_PATHS)
|
||||
|
|
|
@ -519,6 +519,12 @@ endif
|
|||
|
||||
include $(topsrcdir)/config/static-checking-config.mk
|
||||
|
||||
ifdef MOZ_SHARK
|
||||
OS_CFLAGS += -F/System/Library/PrivateFrameworks
|
||||
OS_CXXFLAGS += -F/System/Library/PrivateFrameworks
|
||||
OS_LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD
|
||||
endif # ifdef MOZ_SHARK
|
||||
|
||||
CFLAGS = $(OS_CFLAGS)
|
||||
CXXFLAGS = $(OS_CXXFLAGS)
|
||||
LDFLAGS = $(OS_LDFLAGS) $(MOZ_FIX_LINK_PATHS)
|
||||
|
|
|
@ -84,6 +84,150 @@ void passed(const char* test)
|
|||
printf("TEST-PASS | %s\n", test);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Code profiling
|
||||
//
|
||||
static const char* gCurrentProfile;
|
||||
static PRBool gProfilerTriedInit = PR_FALSE;
|
||||
static PRBool gProfilerInited = PR_FALSE;
|
||||
|
||||
// Platform profilers must implement these functions.
|
||||
// Init and deinit are guaranteed to only be called once, and
|
||||
// StartProfile/StopProfile may assume that they are only called
|
||||
// when the profiler has successfully been initialized.
|
||||
static PRBool _PlatformInitProfiler();
|
||||
static PRBool _PlatformStartProfile(const char* profileName);
|
||||
static PRBool _PlatformStopProfile(const char* profileName);
|
||||
static PRBool _PlatformDeinitProfiler();
|
||||
|
||||
/**
|
||||
* If the build has been configured properly, start the best code profiler
|
||||
* available on this platform.
|
||||
*
|
||||
* This is NOT thread safe.
|
||||
*
|
||||
* @precondition Profiling is not started
|
||||
* @param profileName A descriptive name for this profiling run. Every
|
||||
* attempt is made to name the profile data according
|
||||
* to this name, but check your platform's profiler
|
||||
* documentation for what this means.
|
||||
* @return PR_TRUE if profiling was available and successfully started.
|
||||
* @see StopProfiling
|
||||
*/
|
||||
static PRBool
|
||||
StartProfiling(const char* profileName)
|
||||
{
|
||||
if (!gProfilerTriedInit) {
|
||||
gProfilerTriedInit = PR_TRUE;
|
||||
gProfilerInited = _PlatformInitProfiler();
|
||||
}
|
||||
if (!gProfilerInited)
|
||||
return PR_FALSE;
|
||||
|
||||
NS_ASSERTION(profileName, "need a name for this profile");
|
||||
NS_PRECONDITION(!gCurrentProfile, "started a new profile before stopping another");
|
||||
|
||||
PRBool rv = _PlatformStartProfile(profileName);
|
||||
gCurrentProfile = profileName;
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the platform's profiler. For what this means, what happens after
|
||||
* stopping, and how the profile data can be accessed, check the
|
||||
* documentation of your platform's profiler.
|
||||
*
|
||||
* This is NOT thread safe.
|
||||
*
|
||||
* @precondition Profiling was started
|
||||
* @return PR_TRUE if profiling was successfully stopped.
|
||||
* @see StartProfiling
|
||||
*/
|
||||
static PRBool
|
||||
StopProfiling()
|
||||
{
|
||||
NS_ASSERTION(gProfilerTriedInit, "tried to stop profile before starting one");
|
||||
if (!gProfilerInited)
|
||||
return PR_FALSE;
|
||||
|
||||
NS_PRECONDITION(gCurrentProfile, "tried to stop profile before starting one");
|
||||
|
||||
const char* profileName = gCurrentProfile;
|
||||
gCurrentProfile = 0;
|
||||
return _PlatformStopProfile(profileName);
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// Shark impl
|
||||
#if defined(MOZ_SHARK)
|
||||
#include <CHUD/CHUD.h>
|
||||
|
||||
static PRBool
|
||||
_PlatformInitProfiler()
|
||||
{
|
||||
if (chudSuccess != chudInitialize())
|
||||
return PR_FALSE;
|
||||
if (chudSuccess != chudAcquireRemoteAccess()) {
|
||||
NS_WARNING("Couldn't connect to Shark. Is it running and in Programmatic mode (Shift-Cmd-R)?");
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
_PlatformStartProfile(const char* profileName)
|
||||
{
|
||||
return (chudSuccess == chudStartRemotePerfMonitor(profileName)) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
_PlatformStopProfile(const char* profileName)
|
||||
{
|
||||
return (chudSuccess == chudStopRemotePerfMonitor()) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
_PlatformDeinitProfiler()
|
||||
{
|
||||
return (chudIsRemoteAccessAcquired()
|
||||
&& chudSuccess == chudReleaseRemoteAccess()) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// Default, no-profiler impl
|
||||
#else
|
||||
|
||||
static PRBool
|
||||
_PlatformInitProfiler()
|
||||
{
|
||||
NS_WARNING("Profiling is not available/configured for your platform.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
static PRBool
|
||||
_PlatformStartProfile(const char* profileName)
|
||||
{
|
||||
NS_WARNING("Profiling is not available/configured for your platform.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
static PRBool
|
||||
_PlatformStopProfile(const char* profileName)
|
||||
{
|
||||
NS_WARNING("Profiling is not available/configured for your platform.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
static PRBool
|
||||
_PlatformDeinitProfiler()
|
||||
{
|
||||
NS_WARNING("Profiling is not available/configured for your platform.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class ScopedXPCOM
|
||||
{
|
||||
|
@ -104,6 +248,10 @@ class ScopedXPCOM
|
|||
|
||||
~ScopedXPCOM()
|
||||
{
|
||||
if (gProfilerInited)
|
||||
if (!_PlatformDeinitProfiler())
|
||||
NS_WARNING("Problem shutting down profiler");
|
||||
|
||||
if (mServMgr)
|
||||
{
|
||||
NS_RELEASE(mServMgr);
|
||||
|
|
Загрузка…
Ссылка в новой задаче