From 7e3b302b2747357a2fc3795049a5422c526080fd Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Wed, 30 May 2012 12:47:19 -0400 Subject: [PATCH] Bug 759532 - Expose Enter/ExitProfileLabel to JS. r=ehsan --HG-- extra : rebase_source : e1dbc7995ce2dfd52ece4c3fd3d76cc6cd95896f --- tools/profiler/nsIProfiler.idl | 2 ++ tools/profiler/nsProfiler.cpp | 18 ++++++++++++++++++ tools/profiler/sps_sampler.h | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/tools/profiler/nsIProfiler.idl b/tools/profiler/nsIProfiler.idl index 6bd847a27ddc..75dc350c842b 100644 --- a/tools/profiler/nsIProfiler.idl +++ b/tools/profiler/nsIProfiler.idl @@ -18,6 +18,8 @@ interface nsIProfiler : nsISupports boolean IsActive(); void GetResponsivenessTimes(out PRUint32 aCount, [retval, array, size_is(aCount)] out double aResult); void GetFeatures(out PRUint32 aCount, [retval, array, size_is(aCount)] out string aFeatures); + void EnterProfileLabel(in string aLabel); + void ExitProfileLabel(); /** * Returns a JSON string of an array of shared library objects. diff --git a/tools/profiler/nsProfiler.cpp b/tools/profiler/nsProfiler.cpp index a1acb44c4d73..3e061a58eb4d 100644 --- a/tools/profiler/nsProfiler.cpp +++ b/tools/profiler/nsProfiler.cpp @@ -169,3 +169,21 @@ nsProfiler::GetFeatures(PRUint32 *aCount, char ***aFeatures) *aCount = len; return NS_OK; } + +NS_IMETHODIMP +nsProfiler::EnterProfileLabel(const char *aLabel) +{ + if (!aLebel) + return NS_ERROR_FAILURE; + + mozilla_sampler_call_enter(aLabel); + return NS_OK; +} + +NS_IMETHODIMP +nsProfiler::ExitProfileLabel() +{ + mozilla_sampler_call_exit_no_handle(); + return NS_OK; +} + diff --git a/tools/profiler/sps_sampler.h b/tools/profiler/sps_sampler.h index 219ae41942e5..41cf71a2d1c2 100644 --- a/tools/profiler/sps_sampler.h +++ b/tools/profiler/sps_sampler.h @@ -277,6 +277,25 @@ inline void mozilla_sampler_call_exit(void *aHandle) stack->pop(); } +inline void mozilla_sampler_call_exit_no_handle() +{ + // check if we've been initialized to avoid calling pthread_getspecific + // with a null tlsStack which will return undefined results. + if (!stack_key_initialized) + return; + + ProfileStack *stack = tlsStack.get(); + // we can't infer whether 'stack' has been initialized + // based on the value of stack_key_intiailized because + // 'stack' is only intialized when a thread is being + // profiled. + if (!stack) { + return; + } + + stack->pop(); +} + inline void mozilla_sampler_add_marker(const char *aMarker) { ProfileStack *stack = tlsStack.get();