Skip to content

Commit

Permalink
Fixing the scoped timer and adding scoped thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Mar 24, 2018
1 parent ca63a77 commit 25ba1d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/apex/apex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tau_listener.hpp"
#include "profiler_listener.hpp"
#if defined(APEX_DEBUG) || defined(APEX_ERROR_HANDLING)
// #define APEX_DEBUG_disabled
#include "apex_error_handling.hpp"
#endif
#include "address_resolution.hpp"
Expand Down
59 changes: 37 additions & 22 deletions src/apex/apex_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,69 +805,84 @@ APEX_EXPORT void recv (uint64_t tag, uint64_t size, uint64_t source_rank, uint64
time on a thread.
*/
class self_stopping_timer {
class scoped_timer {
private:
apex::profiler * p;
bool has_thread;
apex::task_wrapper * twp;
public:
/**
\brief Construct and start an APEX timer.
\param func The address of a function used to identify the timer type
*/
self_stopping_timer(uint64_t func) : p(nullptr), has_thread(false) {
p = apex::start((apex_function_address)func);
scoped_timer(uint64_t func) : twp(nullptr) {
twp = apex::new_task((apex_function_address)func);
apex::start(twp);
}
/**
\brief Construct and start an APEX timer.
\param func The name of a function used to identify the timer type
*/
self_stopping_timer(std::string func) : p(nullptr), has_thread(false) {
p = apex::start(func);
scoped_timer(std::string func) : twp(nullptr) {
twp = apex::new_task(func);
apex::start(twp);
}
/**
\brief Register a new thread with APEX, then construct and start an APEX timer.
\param func The address of a function used to identify the timer type
\param thread_name The name of this new worker thread in the runtime
*/
self_stopping_timer(uint64_t func, const char * thread_name)
: p(nullptr), has_thread(true) {
apex::register_thread(thread_name);
p = apex::start((apex_function_address)func);
scoped_timer(uint64_t func, apex::task_wrapper * parent)
: twp(nullptr) {
twp = apex::new_task((apex_function_address)func, UINTMAX_MAX, parent);
apex::start(twp);
}
/**
\brief Register a new thread with APEX, then construct and start an APEX timer.
\param func The name of a function used to identify the timer type
\param thread_name The name of this new worker thread in the runtime
*/
self_stopping_timer(std::string func, const char * thread_name = nullptr)
: p(nullptr), has_thread(true) {
apex::register_thread(thread_name);
p = apex::start(func);
scoped_timer(std::string func, apex::task_wrapper * parent)
: twp(nullptr) {
twp = apex::new_task(func, UINTMAX_MAX, parent);
apex::start(twp);
}
/**
\brief Stop the APEX timer.
*/
void stop(void) {
if (p != nullptr) {
apex::stop(p);
p= nullptr;
if (twp != nullptr) {
apex::stop(twp);
twp = nullptr;
}
/**
\brief Destructor.
*/
}
~self_stopping_timer() {
~scoped_timer() {
stop();
if (has_thread) {
apex::exit_thread();
}
}

/*
\brief Get the internal task wrapper object
*/
apex::task_wrapper * get_task_wrapper(void) {
return twp;
}
};

class scoped_thread {
public:
scoped_thread(const std::string& thread_name) {
apex::register_thread(thread_name);
}
~scoped_thread() {
apex::exit_thread();
}
};

/**
Expand Down

0 comments on commit 25ba1d9

Please sign in to comment.