diff options
Diffstat (limited to 'tools/profiler/public')
-rw-r--r-- | tools/profiler/public/MicroGeckoProfiler.h | 65 | ||||
-rw-r--r-- | tools/profiler/public/ProfilerControl.h | 14 |
2 files changed, 52 insertions, 27 deletions
diff --git a/tools/profiler/public/MicroGeckoProfiler.h b/tools/profiler/public/MicroGeckoProfiler.h index 7b735e1eec..c23142f07f 100644 --- a/tools/profiler/public/MicroGeckoProfiler.h +++ b/tools/profiler/public/MicroGeckoProfiler.h @@ -34,6 +34,10 @@ extern MOZ_EXPORT void uprofiler_unregister_thread(); extern MOZ_EXPORT void uprofiler_simple_event_marker( const char* name, char phase, int num_args, const char** arg_names, const unsigned char* arg_types, const unsigned long long* arg_values); + +extern MOZ_EXPORT void uprofiler_simple_event_marker_with_stack( + const char* name, char phase, int num_args, const char** arg_names, + const unsigned char* arg_types, const unsigned long long* arg_values); #ifdef __cplusplus } @@ -60,6 +64,10 @@ struct UprofilerFuncPtrs { const char** arg_names, const unsigned char* arg_types, const unsigned long long* arg_values); + void (*simple_event_marker_with_stack)(const char* name, char phase, + int num_args, const char** arg_names, + const unsigned char* arg_types, + const unsigned long long* arg_values); }; #pragma GCC diagnostic push @@ -77,6 +85,12 @@ static void simple_event_marker_noop(const char* name, char phase, int num_args, /* no-op */ } +static void simple_event_marker_with_stack_noop( + const char* name, char phase, int num_args, const char** arg_names, + const unsigned char* arg_types, const unsigned long long* arg_values) { + /* no-op */ +} + #pragma GCC diagnostic pop #if defined(_WIN32) @@ -88,7 +102,7 @@ static void simple_event_marker_noop(const char* name, char phase, int num_args, #if defined(_WIN32) # define UPROFILER_GET_SYM(handle, sym) GetProcAddress(handle, sym) #else -# define UPROFILER_GET_SYM(handle, sym) dlsym(handle, sym) +# define UPROFILER_GET_SYM(handle, sym) (typeof(sym)*)(dlsym(handle, #sym)) #endif #if defined(_WIN32) @@ -98,33 +112,30 @@ static void simple_event_marker_noop(const char* name, char phase, int num_args, fprintf(stderr, "%s error: %s\n", #func, dlerror()); #endif +#define FETCH(func) \ + uprofiler.func = UPROFILER_GET_SYM(handle, uprofiler_##func); \ + if (!uprofiler.func) { \ + UPROFILER_PRINT_ERROR(uprofiler_##func); \ + uprofiler.func = func##_noop; \ + } + +#define UPROFILER_VISIT() \ + FETCH(register_thread) \ + FETCH(unregister_thread) \ + FETCH(simple_event_marker) \ + FETCH(simple_event_marker_with_stack) + // Assumes that a variable of type UprofilerFuncPtrs, named uprofiler // is accessible in the scope -#define UPROFILER_GET_FUNCTIONS() \ - void* handle = UPROFILER_OPENLIB(); \ - if (!handle) { \ - UPROFILER_PRINT_ERROR(UPROFILER_OPENLIB); \ - uprofiler.register_thread = register_thread_noop; \ - uprofiler.unregister_thread = unregister_thread_noop; \ - uprofiler.simple_event_marker = simple_event_marker_noop; \ - } \ - uprofiler.register_thread = \ - UPROFILER_GET_SYM(handle, "uprofiler_register_thread"); \ - if (!uprofiler.register_thread) { \ - UPROFILER_PRINT_ERROR(uprofiler_unregister_thread); \ - uprofiler.register_thread = register_thread_noop; \ - } \ - uprofiler.unregister_thread = \ - UPROFILER_GET_SYM(handle, "uprofiler_unregister_thread"); \ - if (!uprofiler.unregister_thread) { \ - UPROFILER_PRINT_ERROR(uprofiler_unregister_thread); \ - uprofiler.unregister_thread = unregister_thread_noop; \ - } \ - uprofiler.simple_event_marker = \ - UPROFILER_GET_SYM(handle, "uprofiler_simple_event_marker"); \ - if (!uprofiler.simple_event_marker) { \ - UPROFILER_PRINT_ERROR(uprofiler_simple_event_marker); \ - uprofiler.simple_event_marker = simple_event_marker_noop; \ - } +#define UPROFILER_GET_FUNCTIONS() \ + void* handle = UPROFILER_OPENLIB(); \ + if (!handle) { \ + UPROFILER_PRINT_ERROR(UPROFILER_OPENLIB); \ + uprofiler.register_thread = register_thread_noop; \ + uprofiler.unregister_thread = unregister_thread_noop; \ + uprofiler.simple_event_marker = simple_event_marker_noop; \ + uprofiler.simple_event_marker_with_stack = simple_event_with_stack_noop; \ + } \ + UPROFILER_VISIT() #endif // MICRO_GECKO_PROFILER diff --git a/tools/profiler/public/ProfilerControl.h b/tools/profiler/public/ProfilerControl.h index 466d15eb69..ac145fac00 100644 --- a/tools/profiler/public/ProfilerControl.h +++ b/tools/profiler/public/ProfilerControl.h @@ -40,6 +40,8 @@ static inline void profiler_init(void* stackTop) {} static inline void profiler_shutdown( IsFastShutdown aIsFastShutdown = IsFastShutdown::No) {} +static inline void profiler_lookup_download_directory() {} + #else // !MOZ_GECKO_PROFILER # include "BaseProfiler.h" @@ -123,6 +125,18 @@ void profiler_ensure_started( const char** aFilters, uint32_t aFilterCount, uint64_t aActiveTabID, const mozilla::Maybe<double>& aDuration = mozilla::Nothing()); +// Tell the profiler to look up the download directory for writing profiles. +// With some features, such as signal control, we need to know the location of +// a directory where we can save profiles to disk. Because we start the +// profiler before we start the directory service, we can't access the +// download directory at profiler startup. Similarly, when we need to get the +// directory, we often can't, as we're running in non-main-thread contexts +// that don't have access to the directory service. This function gives us a +// third option, by giving us a hook to look for the download directory when +// the time is right. This might be triggered internally (e.g. when we start +// profiling), or externally, e.g. after the directory service is initialised. +void profiler_lookup_download_directory(); + //--------------------------------------------------------------------------- // Control the profiler //--------------------------------------------------------------------------- |