From 1dc79ac3e9866647efb84aa3ed563c95776e947a Mon Sep 17 00:00:00 2001 From: PerfStubs Upstream Date: Mon, 27 Nov 2023 15:03:51 -0800 Subject: [PATCH] perfstubs 2023-11-27 (845d0702) Code extracted from: https://github.com/khuck/perfstubs.git at commit 845d070265c7ab1f995edec18ecb86a5d954b046 (master). Upstream Shortlog ----------------- --- LICENSE | 2 +- README.md | 2 +- perfstubs_api/README.md | 6 +- perfstubs_api/config.h.in | 2 +- perfstubs_api/timer.c | 381 ++++++++++++++++---------------------- perfstubs_api/timer.h | 17 +- perfstubs_api/tool.h | 2 +- 7 files changed, 171 insertions(+), 241 deletions(-) diff --git a/LICENSE b/LICENSE index b10754dbe6..667733e1f6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2019-2020, Kevin Huck +Copyright (c) 2019-2022, Kevin Huck and University of Oregon All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 75f77ec1bb..60bcf5565f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PerfStubs -Copyright (c) 2019-2020 University of Oregon +Copyright (c) 2019-2022 University of Oregon Distributed under the BSD Software License (See accompanying file LICENSE.txt) diff --git a/perfstubs_api/README.md b/perfstubs_api/README.md index b0a86dfb3e..cb1579599c 100644 --- a/perfstubs_api/README.md +++ b/perfstubs_api/README.md @@ -1,6 +1,6 @@ -# Profiling Interface for ADIOS2 +# Profiling Interface for Libraries and Applications -Copyright (c) 2019-2020 University of Oregon +Copyright (c) 2019-2022 University of Oregon Distributed under the BSD Software License (See accompanying file LICENSE.txt) @@ -10,7 +10,7 @@ This is a generic design and implementation for other libraries and tools. ## Todo Items - [x] Make the interface generic. - [x] Replace ADIOST-specific symbols with generic versions that will be - implemented by interested measurement libraries (i.e. Score-P). + implemented by interested measurement libraries (i.e. Score-P). - ~~[ ] New environment variable specifying location of library containing function implementations.~~ - [x] Remove dynamic-linking specific approach (checking ```LD_PRELOAD```) diff --git a/perfstubs_api/config.h.in b/perfstubs_api/config.h.in index 222b53cc62..afc84f1418 100644 --- a/perfstubs_api/config.h.in +++ b/perfstubs_api/config.h.in @@ -1,5 +1,5 @@ // the configured options and settings for Tutorial -// Copyright (c) 2019-2020 University of Oregon +// Copyright (c) 2019-2022 University of Oregon // Distributed under the BSD Software License // (See accompanying file LICENSE.txt) #define PerfStubs_VERSION_MAJOR @PerfStubs_VERSION_MAJOR@ diff --git a/perfstubs_api/timer.c b/perfstubs_api/timer.c index b4177e5521..d219ea5e5b 100644 --- a/perfstubs_api/timer.c +++ b/perfstubs_api/timer.c @@ -1,22 +1,20 @@ -// Copyright (c) 2019-2020 University of Oregon +// Copyright (c) 2019-2022 University of Oregon // Distributed under the BSD Software License // (See accompanying file LICENSE.txt) #ifndef _GNU_SOURCE #define _GNU_SOURCE // needed to define RTLD_DEFAULT #endif +#include #include #include #include -#include #include "pthread.h" #ifndef PERFSTUBS_USE_TIMERS #define PERFSTUBS_USE_TIMERS #endif #include "perfstubs_api/timer.h" -#define MAX_TOOLS 1 - /* Make sure that the Timer singleton is constructed when the * library is loaded. This will ensure (on linux, anyway) that * we can assert that we have m_Initialized on the main thread. */ @@ -39,30 +37,30 @@ static void make_key(void) { /* Function pointers */ -ps_initialize_t initialize_functions[MAX_TOOLS]; -ps_finalize_t finalize_functions[MAX_TOOLS]; -ps_pause_measurement_t pause_measurement_functions[MAX_TOOLS]; -ps_resume_measurement_t resume_measurement_functions[MAX_TOOLS]; -ps_register_thread_t register_thread_functions[MAX_TOOLS]; -ps_dump_data_t dump_data_functions[MAX_TOOLS]; -ps_timer_create_t timer_create_functions[MAX_TOOLS]; -ps_timer_start_t timer_start_functions[MAX_TOOLS]; -ps_timer_stop_t timer_stop_functions[MAX_TOOLS]; -ps_start_string_t start_string_functions[MAX_TOOLS]; -ps_stop_string_t stop_string_functions[MAX_TOOLS]; -ps_stop_current_t stop_current_functions[MAX_TOOLS]; -ps_set_parameter_t set_parameter_functions[MAX_TOOLS]; -ps_dynamic_phase_start_t dynamic_phase_start_functions[MAX_TOOLS]; -ps_dynamic_phase_stop_t dynamic_phase_stop_functions[MAX_TOOLS]; -ps_create_counter_t create_counter_functions[MAX_TOOLS]; -ps_sample_counter_t sample_counter_functions[MAX_TOOLS]; -ps_set_metadata_t set_metadata_functions[MAX_TOOLS]; -ps_get_timer_data_t get_timer_data_functions[MAX_TOOLS]; -ps_get_counter_data_t get_counter_data_functions[MAX_TOOLS]; -ps_get_metadata_t get_metadata_functions[MAX_TOOLS]; -ps_free_timer_data_t free_timer_data_functions[MAX_TOOLS]; -ps_free_counter_data_t free_counter_data_functions[MAX_TOOLS]; -ps_free_metadata_t free_metadata_functions[MAX_TOOLS]; +ps_initialize_t initialize_function; +ps_finalize_t finalize_function; +ps_pause_measurement_t pause_measurement_function; +ps_resume_measurement_t resume_measurement_function; +ps_register_thread_t register_thread_function; +ps_dump_data_t dump_data_function; +ps_timer_create_t timer_create_function; +ps_timer_start_t timer_start_function; +ps_timer_stop_t timer_stop_function; +ps_start_string_t start_string_function; +ps_stop_string_t stop_string_function; +ps_stop_current_t stop_current_function; +ps_set_parameter_t set_parameter_function; +ps_dynamic_phase_start_t dynamic_phase_start_function; +ps_dynamic_phase_stop_t dynamic_phase_stop_function; +ps_create_counter_t create_counter_function; +ps_sample_counter_t sample_counter_function; +ps_set_metadata_t set_metadata_function; +ps_get_timer_data_t get_timer_data_function; +ps_get_counter_data_t get_counter_data_function; +ps_get_metadata_t get_metadata_function; +ps_free_timer_data_t free_timer_data_function; +ps_free_counter_data_t free_counter_data_function; +ps_free_metadata_t free_metadata_function; #ifdef PERFSTUBS_USE_STATIC @@ -102,93 +100,94 @@ PS_WEAK_PRE void ps_tool_free_counter_data(ps_tool_counter_data_t *) PS_WEAK_POS PS_WEAK_PRE void ps_tool_free_metadata(ps_tool_metadata_t *) PS_WEAK_POST; #endif -void initialize_library() { +void initialize_library(void) { #ifdef PERFSTUBS_USE_STATIC /* The initialization function is the only required one */ - initialize_functions[0] = &ps_tool_initialize; - if (initialize_functions[0] == NULL) { + initialize_function = &ps_tool_initialize; + if (initialize_function == NULL) { perfstubs_initialized = PERFSTUBS_FAILURE; return; } - printf("Found ps_tool_initialize(), registering tool\n"); - finalize_functions[0] = &ps_tool_finalize; - pause_measurement_functions[0] = &ps_tool_pause_measurement; - resume_measurement_functions[0] = &ps_tool_resume_measurement; - register_thread_functions[0] = &ps_tool_register_thread; - dump_data_functions[0] = &ps_tool_dump_data; - timer_create_functions[0] = &ps_tool_timer_create; - timer_start_functions[0] = &ps_tool_timer_start; - timer_stop_functions[0] = &ps_tool_timer_stop; - start_string_functions[0] = &ps_tool_start_string; - stop_string_functions[0] = &ps_tool_stop_string; - stop_current_functions[0] = &ps_tool_stop_current; - set_parameter_functions[0] = &ps_tool_set_parameter; - dynamic_phase_start_functions[0] = &ps_tool_dynamic_phase_start; - dynamic_phase_stop_functions[0] = &ps_tool_dynamic_phase_stop; - create_counter_functions[0] = &ps_tool_create_counter; - sample_counter_functions[0] = &ps_tool_sample_counter; - set_metadata_functions[0] = &ps_tool_set_metadata; - get_timer_data_functions[0] = &ps_tool_get_timer_data; - get_counter_data_functions[0] = &ps_tool_get_counter_data; - get_metadata_functions[0] = &ps_tool_get_metadata; - free_timer_data_functions[0] = &ps_tool_free_timer_data; - free_counter_data_functions[0] = &ps_tool_free_counter_data; - free_metadata_functions[0] = &ps_tool_free_metadata; + // removing printf statement for now, it's too noisy. + //printf("Found ps_tool_initialize(), registering tool\n"); + finalize_function = &ps_tool_finalize; + pause_measurement_function = &ps_tool_pause_measurement; + resume_measurement_function = &ps_tool_resume_measurement; + register_thread_function = &ps_tool_register_thread; + dump_data_function = &ps_tool_dump_data; + timer_create_function = &ps_tool_timer_create; + timer_start_function = &ps_tool_timer_start; + timer_stop_function = &ps_tool_timer_stop; + start_string_function = &ps_tool_start_string; + stop_string_function = &ps_tool_stop_string; + stop_current_function = &ps_tool_stop_current; + set_parameter_function = &ps_tool_set_parameter; + dynamic_phase_start_function = &ps_tool_dynamic_phase_start; + dynamic_phase_stop_function = &ps_tool_dynamic_phase_stop; + create_counter_function = &ps_tool_create_counter; + sample_counter_function = &ps_tool_sample_counter; + set_metadata_function = &ps_tool_set_metadata; + get_timer_data_function = &ps_tool_get_timer_data; + get_counter_data_function = &ps_tool_get_counter_data; + get_metadata_function = &ps_tool_get_metadata; + free_timer_data_function = &ps_tool_free_timer_data; + free_counter_data_function = &ps_tool_free_counter_data; + free_metadata_function = &ps_tool_free_metadata; #else - initialize_functions[0] = + initialize_function = (ps_initialize_t)dlsym(RTLD_DEFAULT, "ps_tool_initialize"); - if (initialize_functions[0] == NULL) { + if (initialize_function == NULL) { perfstubs_initialized = PERFSTUBS_FAILURE; return; } printf("Found ps_tool_initialize(), registering tool\n"); - finalize_functions[0] = + finalize_function = (ps_finalize_t)dlsym(RTLD_DEFAULT, "ps_tool_finalize"); - pause_measurement_functions[0] = + pause_measurement_function = (ps_pause_measurement_t)dlsym(RTLD_DEFAULT, "ps_tool_pause_measurement"); - resume_measurement_functions[0] = + resume_measurement_function = (ps_resume_measurement_t)dlsym(RTLD_DEFAULT, "ps_tool_resume_measurement"); - register_thread_functions[0] = + register_thread_function = (ps_register_thread_t)dlsym(RTLD_DEFAULT, "ps_tool_register_thread"); - dump_data_functions[0] = + dump_data_function = (ps_dump_data_t)dlsym(RTLD_DEFAULT, "ps_tool_dump_data"); - timer_create_functions[0] = + timer_create_function = (ps_timer_create_t)dlsym(RTLD_DEFAULT, - "ps_tool_timer_create"); - timer_start_functions[0] = + "ps_tool_timer_create"); + timer_start_function = (ps_timer_start_t)dlsym(RTLD_DEFAULT, "ps_tool_timer_start"); - timer_stop_functions[0] = + timer_stop_function = (ps_timer_stop_t)dlsym(RTLD_DEFAULT, "ps_tool_timer_stop"); - start_string_functions[0] = + start_string_function = (ps_start_string_t)dlsym(RTLD_DEFAULT, "ps_tool_start_string"); - stop_string_functions[0] = + stop_string_function = (ps_stop_string_t)dlsym(RTLD_DEFAULT, "ps_tool_stop_string"); - stop_current_functions[0] = + stop_current_function = (ps_stop_current_t)dlsym(RTLD_DEFAULT, "ps_tool_stop_current"); - set_parameter_functions[0] = + set_parameter_function = (ps_set_parameter_t)dlsym(RTLD_DEFAULT, "ps_tool_set_parameter"); - dynamic_phase_start_functions[0] = (ps_dynamic_phase_start_t)dlsym( - RTLD_DEFAULT, "ps_tool_dynamic_phase_start"); - dynamic_phase_stop_functions[0] = (ps_dynamic_phase_stop_t)dlsym( - RTLD_DEFAULT, "ps_tool_dynamic_phase_stop"); - create_counter_functions[0] = (ps_create_counter_t)dlsym( - RTLD_DEFAULT, "ps_tool_create_counter"); - sample_counter_functions[0] = (ps_sample_counter_t)dlsym( - RTLD_DEFAULT, "ps_tool_sample_counter"); - set_metadata_functions[0] = + dynamic_phase_start_function = (ps_dynamic_phase_start_t)dlsym( + RTLD_DEFAULT, "ps_tool_dynamic_phase_start"); + dynamic_phase_stop_function = (ps_dynamic_phase_stop_t)dlsym( + RTLD_DEFAULT, "ps_tool_dynamic_phase_stop"); + create_counter_function = (ps_create_counter_t)dlsym( + RTLD_DEFAULT, "ps_tool_create_counter"); + sample_counter_function = (ps_sample_counter_t)dlsym( + RTLD_DEFAULT, "ps_tool_sample_counter"); + set_metadata_function = (ps_set_metadata_t)dlsym(RTLD_DEFAULT, "ps_tool_set_metadata"); - get_timer_data_functions[0] = (ps_get_timer_data_t)dlsym( - RTLD_DEFAULT, "ps_tool_get_timer_data"); - get_counter_data_functions[0] = (ps_get_counter_data_t)dlsym( - RTLD_DEFAULT, "ps_tool_get_counter_data"); - get_metadata_functions[0] = (ps_get_metadata_t)dlsym( - RTLD_DEFAULT, "ps_tool_get_metadata"); - free_timer_data_functions[0] = (ps_free_timer_data_t)dlsym( - RTLD_DEFAULT, "ps_tool_free_timer_data"); - free_counter_data_functions[0] = (ps_free_counter_data_t)dlsym( - RTLD_DEFAULT, "ps_tool_free_counter_data"); - free_metadata_functions[0] = (ps_free_metadata_t)dlsym( - RTLD_DEFAULT, "ps_tool_free_metadata"); + get_timer_data_function = (ps_get_timer_data_t)dlsym( + RTLD_DEFAULT, "ps_tool_get_timer_data"); + get_counter_data_function = (ps_get_counter_data_t)dlsym( + RTLD_DEFAULT, "ps_tool_get_counter_data"); + get_metadata_function = (ps_get_metadata_t)dlsym( + RTLD_DEFAULT, "ps_tool_get_metadata"); + free_timer_data_function = (ps_free_timer_data_t)dlsym( + RTLD_DEFAULT, "ps_tool_free_timer_data"); + free_counter_data_function = (ps_free_counter_data_t)dlsym( + RTLD_DEFAULT, "ps_tool_free_counter_data"); + free_metadata_function = (ps_free_metadata_t)dlsym( + RTLD_DEFAULT, "ps_tool_free_metadata"); #endif perfstubs_initialized = PERFSTUBS_SUCCESS; /* Increment the number of tools */ @@ -196,7 +195,7 @@ void initialize_library() { } char * ps_make_timer_name_(const char * file, - const char * func, int line) { + const char * func, int line) { /* The length of the line number as a string is floor(log10(abs(num))) */ int string_length = (strlen(file) + strlen(func) + floor(log10(abs(line))) + 12); char * name = calloc(string_length, sizeof(char)); @@ -206,59 +205,41 @@ char * ps_make_timer_name_(const char * file, // used internally to the class static inline void ps_register_thread_internal(void) { - //if (thread_seen == 0) { if (pthread_getspecific(key) == NULL) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - register_thread_functions[i](); - } - //thread_seen = 1; - pthread_setspecific(key, (void*)1UL); + if (register_thread_function != NULL) { + register_thread_function(); + pthread_setspecific(key, (void*)1UL); + } } } /* Initialization */ void ps_initialize_(void) { - int i; /* Only do this once */ if (perfstubs_initialized != PERFSTUBS_UNKNOWN) { return; } initialize_library(); - for (i = 0 ; i < num_tools_registered ; i++) { - initialize_functions[i](); - } - /* No need to register the main thread */ - //thread_seen = 1; - (void) pthread_once(&key_once, make_key); - if (pthread_getspecific(key) == NULL) { - // set the key to 1, indicating we have seen this thread + if (initialize_function != NULL) { + initialize_function(); + (void) pthread_once(&key_once, make_key); pthread_setspecific(key, (void*)1UL); } } void ps_finalize_(void) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (finalize_functions[i] != NULL) - finalize_functions[i](); - } + if (finalize_function != NULL) + finalize_function(); } void ps_pause_measurement_(void) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (pause_measurement_functions[i] != NULL) - pause_measurement_functions[i](); - } + if (pause_measurement_function != NULL) + pause_measurement_function(); } void ps_resume_measurement_(void) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (resume_measurement_functions[i] != NULL) - resume_measurement_functions[i](); - } + if (resume_measurement_function != NULL) + resume_measurement_function(); } void ps_register_thread_(void) { @@ -266,13 +247,10 @@ void ps_register_thread_(void) { } void* ps_timer_create_(const char *timer_name) { - ps_register_thread_internal(); + ps_register_thread_internal(); void ** objects = (void **)calloc(num_tools_registered, sizeof(void*)); - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (timer_create_functions[i] != NULL) - objects[i] = (void *)timer_create_functions[i](timer_name); - } + if (timer_create_function != NULL) + objects = (void *)timer_create_function(timer_name); return (void*)(objects); } @@ -281,14 +259,10 @@ void ps_timer_create_fortran_(void ** object, const char *timer_name) { } void ps_timer_start_(void *timer) { - ps_register_thread_internal(); + ps_register_thread_internal(); void ** objects = (void **)timer; - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (timer_start_functions[i] != NULL && - objects[i] != NULL) - timer_start_functions[i](objects[i]); - } + if (timer_start_function != NULL && objects != NULL) + timer_start_function(objects); } void ps_timer_start_fortran_(void **timer) { @@ -297,12 +271,9 @@ void ps_timer_start_fortran_(void **timer) { void ps_timer_stop_(void *timer) { void ** objects = (void **)timer; - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (timer_stop_functions[i] != NULL && - objects[i] != NULL) - timer_stop_functions[i](objects[i]); - } + if (timer_stop_function != NULL && + objects != NULL) + timer_stop_function(objects); } void ps_timer_stop_fortran_(void **timer) { @@ -310,62 +281,41 @@ void ps_timer_stop_fortran_(void **timer) { } void ps_start_string_(const char *timer_name) { - ps_register_thread_internal(); - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (start_string_functions[i] != NULL) - start_string_functions[i](timer_name); - } + ps_register_thread_internal(); + if (start_string_function != NULL) + start_string_function(timer_name); } void ps_stop_string_(const char *timer_name) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (stop_string_functions[i] != NULL) - stop_string_functions[i](timer_name); - } + if (stop_string_function != NULL) + stop_string_function(timer_name); } void ps_stop_current_(void) { - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (stop_current_functions[i] != NULL) - stop_current_functions[i](); - } + if (stop_current_function != NULL) + stop_current_function(); } void ps_set_parameter_(const char * parameter_name, int64_t parameter_value) { - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (set_parameter_functions[i] != NULL) - set_parameter_functions[i](parameter_name, parameter_value); - } + if (set_parameter_function != NULL) + set_parameter_function(parameter_name, parameter_value); } void ps_dynamic_phase_start_(const char *phase_prefix, int iteration_index) { - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (dynamic_phase_start_functions[i] != NULL) - dynamic_phase_start_functions[i](phase_prefix, iteration_index); - } + if (dynamic_phase_start_function != NULL) + dynamic_phase_start_function(phase_prefix, iteration_index); } void ps_dynamic_phase_stop_(const char *phase_prefix, int iteration_index) { - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (dynamic_phase_stop_functions[i] != NULL) - dynamic_phase_stop_functions[i](phase_prefix, iteration_index); - } + if (dynamic_phase_stop_function != NULL) + dynamic_phase_stop_function(phase_prefix, iteration_index); } void* ps_create_counter_(const char *name) { - ps_register_thread_internal(); + ps_register_thread_internal(); void ** objects = (void **)calloc(num_tools_registered, sizeof(void*)); - int i; - for (i = 0 ; i < num_tools_registered ; i++) { - if (create_counter_functions[i] != NULL) - objects[i] = (void*)create_counter_functions[i](name); - } + if (create_counter_function != NULL) + objects = (void*)create_counter_function(name); return (void*)(objects); } @@ -375,12 +325,9 @@ void ps_create_counter_fortran_(void ** object, const char *name) { void ps_sample_counter_(void *counter, const double value) { void ** objects = (void **)counter; - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (sample_counter_functions[i] != NULL && - objects[i] != NULL) - sample_counter_functions[i](objects[i], value); - } + if (sample_counter_function != NULL && + objects != NULL) + sample_counter_function(objects, value); } void ps_sample_counter_fortran_(void **counter, const double value) { @@ -388,61 +335,43 @@ void ps_sample_counter_fortran_(void **counter, const double value) { } void ps_set_metadata_(const char *name, const char *value) { - ps_register_thread_internal(); - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (set_metadata_functions[i] != NULL) - set_metadata_functions[i](name, value); - } + ps_register_thread_internal(); + if (set_metadata_function != NULL) + set_metadata_function(name, value); } void ps_dump_data_(void) { - int i; - for (i = 0; i < num_tools_registered ; i++) { - if (dump_data_functions[i] != NULL) - dump_data_functions[i](); - } + if (dump_data_function != NULL) + dump_data_function(); } -void ps_get_timer_data_(ps_tool_timer_data_t *timer_data, int tool_id) { - if (tool_id < num_tools_registered) { - if (get_timer_data_functions[tool_id] != NULL) - get_timer_data_functions[tool_id](timer_data); - } +void ps_get_timer_data_(ps_tool_timer_data_t *timer_data) { + if (get_timer_data_function != NULL) + get_timer_data_function(timer_data); } -void ps_get_counter_data_(ps_tool_counter_data_t *counter_data, int tool_id) { - if (tool_id < num_tools_registered) { - if (get_counter_data_functions[tool_id] != NULL) - get_counter_data_functions[tool_id](counter_data); - } +void ps_get_counter_data_(ps_tool_counter_data_t *counter_data) { + if (get_counter_data_function != NULL) + get_counter_data_function(counter_data); } -void ps_get_metadata_(ps_tool_metadata_t *metadata, int tool_id) { - if (tool_id < num_tools_registered) { - if (get_metadata_functions[tool_id] != NULL) - get_metadata_functions[tool_id](metadata); - } +void ps_get_metadata_(ps_tool_metadata_t *metadata) { + if (get_metadata_function != NULL) + get_metadata_function(metadata); } -void ps_free_timer_data_(ps_tool_timer_data_t *timer_data, int tool_id) { - if (tool_id < num_tools_registered) { - if (free_timer_data_functions[tool_id] != NULL) - free_timer_data_functions[tool_id](timer_data); - } +void ps_free_timer_data_(ps_tool_timer_data_t *timer_data) { + if (free_timer_data_function != NULL) + free_timer_data_function(timer_data); } -void ps_free_counter_data_(ps_tool_counter_data_t *counter_data, int tool_id) { - if (tool_id < num_tools_registered) { - if (free_counter_data_functions[tool_id] != NULL) - free_counter_data_functions[tool_id](counter_data); - } +void ps_free_counter_data_(ps_tool_counter_data_t *counter_data) { + if (free_counter_data_function != NULL) + free_counter_data_function(counter_data); } -void ps_free_metadata_(ps_tool_metadata_t *metadata, int tool_id) { - if (tool_id < num_tools_registered) { - if (free_metadata_functions[tool_id] != NULL) - free_metadata_functions[tool_id](metadata); - } +void ps_free_metadata_(ps_tool_metadata_t *metadata) { + if (free_metadata_function != NULL) + free_metadata_function(metadata); } diff --git a/perfstubs_api/timer.h b/perfstubs_api/timer.h index c806c9ed64..6bc36978f5 100644 --- a/perfstubs_api/timer.h +++ b/perfstubs_api/timer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 University of Oregon +// Copyright (c) 2019-2022 University of Oregon // Distributed under the BSD Software License // (See accompanying file LICENSE.txt) @@ -24,7 +24,8 @@ * not just the function name. If the compiler doesn't support it, * just use the function name. */ -#if defined(__GNUC__) +/* ISO C doesn't allow __PRETTY_FUNCTION__, so only do it with C++ */ +#if defined(__GNUC__) && defined(__cplusplus) #define __PERFSTUBS_FUNCTION__ __PRETTY_FUNCTION__ #else #define __PERFSTUBS_FUNCTION__ __func__ @@ -75,12 +76,12 @@ void ps_set_metadata_(const char *name, const char *value); /* data query API */ -void ps_get_timer_data_(ps_tool_timer_data_t *timer_data, int tool_id); -void ps_get_counter_data_(ps_tool_counter_data_t *counter_data, int tool_id); -void ps_get_metadata_(ps_tool_metadata_t *metadata, int tool_id); -void ps_free_timer_data_(ps_tool_timer_data_t *timer_data, int tool_id); -void ps_free_counter_data_(ps_tool_counter_data_t *counter_data, int tool_id); -void ps_free_metadata_(ps_tool_metadata_t *metadata, int tool_id); +void ps_get_timer_data_(ps_tool_timer_data_t *timer_data); +void ps_get_counter_data_(ps_tool_counter_data_t *counter_data); +void ps_get_metadata_(ps_tool_metadata_t *metadata); +void ps_free_timer_data_(ps_tool_timer_data_t *timer_data); +void ps_free_counter_data_(ps_tool_counter_data_t *counter_data); +void ps_free_metadata_(ps_tool_metadata_t *metadata); char* ps_make_timer_name_(const char * file, const char * func, int line); diff --git a/perfstubs_api/tool.h b/perfstubs_api/tool.h index d00f9ede3d..8668ffa9d8 100644 --- a/perfstubs_api/tool.h +++ b/perfstubs_api/tool.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 University of Oregon +// Copyright (c) 2019-2022 University of Oregon // Distributed under the BSD Software License // (See accompanying file LICENSE.txt)