Skip to content

Commit

Permalink
Re-enablling ability to get vector of available profiles, updated per…
Browse files Browse the repository at this point in the history
…iodic example
  • Loading branch information
khuck committed Mar 4, 2021
1 parent e15e1f6 commit 3f32834
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 17 deletions.
13 changes: 10 additions & 3 deletions src/apex/apex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1821,11 +1830,9 @@ double current_power_high(void) {
return power;
}

/*
std::vector<std::string> get_available_profiles() {
std::vector<task_identifier>& get_available_profiles() {
return apex::__instance()->the_profiler_listener->get_available_profiles();
}
*/

void print_options() {
// if APEX is disabled, do nothing.
Expand Down
17 changes: 14 additions & 3 deletions src/apex/apex_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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<std::string> get_available_profiles();
APEX_EXPORT std::vector<task_identifier>& get_available_profiles();

/**
\brief Get the current power reading
Expand Down
2 changes: 1 addition & 1 deletion src/apex/profiler_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ std::unordered_set<profile*> 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.
Expand Down
15 changes: 13 additions & 2 deletions src/apex/profiler_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> get_available_profiles();
std::vector<task_identifier>& get_available_profiles() {
static std::vector<task_identifier> 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);
Expand Down
27 changes: 19 additions & 8 deletions src/examples/PeriodicPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, 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<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, 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<std::__1::tuple<st... : 400 0.300 120.101 49.897
82: void* std::__1::__thread_proxy<std::__1::tuple<st... : 1 30.089 30.089 12.500
Expand Down
17 changes: 17 additions & 0 deletions src/examples/PeriodicPlugin/apex_periodic_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <memory>
#include <utility>
#include <cstdlib>
Expand All @@ -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;
}

Expand Down

0 comments on commit 3f32834

Please sign in to comment.