diff --git a/src/apex/apex.cpp b/src/apex/apex.cpp index d7ee5587..a037f0c4 100644 --- a/src/apex/apex.cpp +++ b/src/apex/apex.cpp @@ -1802,6 +1802,15 @@ apex_profile* get_profile(const std::string &timer_name) { return nullptr; } +apex_profile* get_profile(const task_identifier &task_id) { + // if APEX is disabled, do nothing. + if (apex_options::disable() == true) { return nullptr; } + profile * tmp = apex::__instance()->the_profiler_listener->get_profile(task_id); + if (tmp != nullptr) + return tmp->get_profile(); + return nullptr; +} + double current_power_high(void) { double power = 0.0; #ifdef APEX_HAVE_RCR @@ -1821,11 +1830,9 @@ double current_power_high(void) { return power; } -/* -std::vector get_available_profiles() { +std::vector& get_available_profiles() { return apex::__instance()->the_profiler_listener->get_available_profiles(); } -*/ void print_options() { // if APEX is disabled, do nothing. diff --git a/src/apex/apex_api.hpp b/src/apex/apex_api.hpp index 7ad96414..c1c7adab 100644 --- a/src/apex/apex_api.hpp +++ b/src/apex/apex_api.hpp @@ -575,6 +575,18 @@ APEX_EXPORT apex_profile* get_profile(apex_function_address function_address); */ APEX_EXPORT apex_profile* get_profile(const std::string &timer_name); +/** + \brief Get the current profile for the specified task_identifier. + + This function will return the current profile for the specified task_identifier. + Because profiles are updated out-of-band, it is possible that this profile + value is out of date. This profile can be either a timer or a sampled value. + + \param task_id The task_identifier of the timer/counter + \return The current profile for that timed function or sampled value. + */ +APEX_EXPORT apex_profile* get_profile(const task_identifier &task_id); + #ifndef DOXYGEN_SHOULD_SKIP_THIS /** @@ -585,10 +597,9 @@ APEX_EXPORT apex_profile* get_profile(const std::string &timer_name); Because profiles are updated out-of-band, it is possible that this profile value is out of date. This profile can be either a timer or a sampled value. - \return A vector of strings containing the list of names. + \return A vector of task_identifier objects */ -/* Disabled, after adding task_identifier support */ -//APEX_EXPORT std::vector get_available_profiles(); +APEX_EXPORT std::vector& get_available_profiles(); /** \brief Get the current power reading diff --git a/src/apex/profiler_listener.cpp b/src/apex/profiler_listener.cpp index 59f9c8d1..58af021f 100644 --- a/src/apex/profiler_listener.cpp +++ b/src/apex/profiler_listener.cpp @@ -225,7 +225,7 @@ std::unordered_set free_profiles; /* Return the requested profile object to the user. * Return nullptr if doesn't exist. */ - profile * profiler_listener::get_profile(task_identifier &id) { + profile * profiler_listener::get_profile(const task_identifier &id) { /* Maybe we aren't processing profiler objects yet? Fire off a request. */ #ifdef APEX_HAVE_HPX // don't schedule an HPX action - just do it. diff --git a/src/apex/profiler_listener.hpp b/src/apex/profiler_listener.hpp index c432c705..b28b782f 100644 --- a/src/apex/profiler_listener.hpp +++ b/src/apex/profiler_listener.hpp @@ -227,11 +227,22 @@ class profiler_listener : public event_listener { // other methods void reset(task_identifier * id); void reset_all(void); - profile * get_profile(task_identifier &id); + profile * get_profile(const task_identifier &id); double get_non_idle_time(void); profile * get_idle_time(void); profile * get_idle_rate(void); - //std::vector get_available_profiles(); + std::vector& get_available_profiles() { + static std::vector ids; + _task_map_mutex.lock(); + if (task_map.size() > ids.size()) { + ids.clear(); + for (auto kv : task_map) { + ids.push_back(kv.first); + } + } + _task_map_mutex.unlock(); + return ids; + } void process_profiles(void); static void process_profiles_wrapper(void); static void consumer_process_profiles_wrapper(void); diff --git a/src/examples/PeriodicPlugin/README.md b/src/examples/PeriodicPlugin/README.md index b08ebf82..ce86b47d 100644 --- a/src/examples/PeriodicPlugin/README.md +++ b/src/examples/PeriodicPlugin/README.md @@ -34,7 +34,7 @@ test 82 Start 82: ExamplePeriodicPlugin 82: Test command: /Users/khuck/src/xpress-apex/build/src/examples/PeriodicPlugin/periodic_policy_test -82: Environment variables: +82: Environment variables: 82: APEX_POLICY=1 82: APEX_SCREEN_OUTPUT=1 82: APEX_PLUGINS_PATH=/Users/khuck/src/xpress-apex/build/src/examples/PeriodicPlugin @@ -51,24 +51,35 @@ test 82 82: Iteration: 1 82: Iteration: 2 ... -82: Iteration: 96 -82: periodic_policy -82: Iteration: 97 82: Iteration: 98 82: periodic_policy +82: Found 2 profiles so far. +82: pthread_join +82: void* std::__1::__thread_proxy >, void (*)(int), int> >(void*) +82: pthread_join : Num Calls : 392 +82: pthread_join : Accumulated : 29.0294 +82: pthread_join : Max : 0.539959 +82: 82: Iteration: 99 82: periodic_policy +82: Found 2 profiles so far. +82: pthread_join +82: void* std::__1::__thread_proxy >, void (*)(int), int> >(void*) +82: pthread_join : Num Calls : 396 +82: pthread_join : Accumulated : 29.5747 +82: pthread_join : Max : 0.545258 +82: 82: Test passed. -82: +82: 82: apex_plugin_finalize 82: apex_openmp_policy finalize -82: +82: 82: Elapsed time: 30.0875 seconds 82: Cores detected: 8 82: Worker Threads observed: 403 82: Available CPU time: 240.7 seconds -82: -82: Timer : #calls | mean | total | % total +82: +82: Timer : #calls | mean | total | % total 82: ------------------------------------------------------------------------------------------------ 82: void* std::__1::__thread_proxy #include #include +#include #include #include #include @@ -27,6 +28,22 @@ int periodic_policy(const apex_context context) { std::cerr << "ERROR: No task_identifier for event!" << std::endl; return APEX_ERROR; } + auto task_ids = apex::get_available_profiles(); + std::stringstream ss; + ss << "Found " << task_ids.size() << " profiles so far.\n"; + for (auto t : task_ids) { + ss << t.get_name() << "\n"; + } + /* Get one specific task_identifier */ + apex::task_identifier tid("pthread_join"); + apex_profile * profile = get_profile(tid); + if (profile) { + ss << "pthread_join : Num Calls : " << profile->calls << "\n"; + ss << "pthread_join : Accumulated : " << profile->accumulated << "\n"; + ss << "pthread_join : Max : " << profile->maximum << "\n"; + } + std::cout << ss.str() << std::endl; + return APEX_NOERROR; }