-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chrome_trace_event' into develop
Conflicts: src/apex/profiler.hpp
- Loading branch information
Showing
8 changed files
with
319 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// Copyright (c) 2014 University of Oregon | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include "trace_event_listener.hpp" | ||
#include "thread_instance.hpp" | ||
#include "apex.hpp" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <memory> | ||
|
||
using namespace std; | ||
|
||
namespace apex { | ||
|
||
bool trace_event_listener::_initialized(false); | ||
|
||
trace_event_listener::trace_event_listener (void) : _terminate(false), | ||
saved_node_id(apex::instance()->get_node_id()) { | ||
std::stringstream ss; | ||
ss << "trace_events." << saved_node_id << ".json"; | ||
trace.open(ss.str()); | ||
trace << fixed << "{\n"; | ||
trace << "\"displayTimeUnit\": \"ns\",\n"; | ||
trace << "\"traceEvents\": [\n"; | ||
trace << "{\"name\": \"program\", \"cat\": \"PERF\", \"ph\": \"B\", \"pid\": \"" << | ||
saved_node_id << "\", \"tid\": \"0\", \"ts\": \"" << profiler::get_time() << "\"},\n"; | ||
_initialized = true; | ||
} | ||
|
||
trace_event_listener::~trace_event_listener (void) { | ||
trace << "{\"name\": \"program\", \"cat\": \"PERF\", \"ph\": \"E\", \"pid\": \"" << | ||
saved_node_id << "\", \"tid\": \"0\", \"ts\": \"" << profiler::get_time() << "\"}\n"; | ||
trace << "]\n}\n" << std::endl; | ||
trace.close(); | ||
_initialized = true; | ||
} | ||
|
||
void trace_event_listener::on_startup(startup_event_data &data) { | ||
APEX_UNUSED(data); | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_dump(dump_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_shutdown(shutdown_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
_terminate = true; | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_new_node(node_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
// set node id | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_new_thread(new_thread_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_exit_thread(event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
inline bool trace_event_listener::_common_start(std::shared_ptr<task_wrapper> &tt_ptr) { | ||
if (!_terminate) { | ||
_mutex.lock(); | ||
trace << "{\"name\": \"" << tt_ptr->task_id->get_name() | ||
<< "\", \"cat\": \"PERF\", \"ph\": \"B\", \"pid\": \"" | ||
<< saved_node_id << "\", \"tid\": " << thread_instance::get_id() | ||
<< ", \"ts\": \"" << tt_ptr->prof->get_start() << "\"},\n"; | ||
_mutex.unlock(); | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool trace_event_listener::on_start(std::shared_ptr<task_wrapper> &tt_ptr) { | ||
return _common_start(tt_ptr); | ||
} | ||
|
||
bool trace_event_listener::on_resume(std::shared_ptr<task_wrapper> &tt_ptr) { | ||
return _common_start(tt_ptr); | ||
} | ||
|
||
inline void trace_event_listener::_common_stop(std::shared_ptr<profiler> &p) { | ||
if (!_terminate) { | ||
_mutex.lock(); | ||
trace << "{\"name\": \"" << p->get_task_id()->get_name() | ||
<< "\", \"cat\": \"PERF\", \"ph\": \"E\", \"pid\": \"" << saved_node_id | ||
<< "\", \"tid\": " << thread_instance::get_id() | ||
<< ", \"ts\": \"" << p->get_stop() << "\"},\n"; | ||
_mutex.unlock(); | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_stop(std::shared_ptr<profiler> &p) { | ||
return _common_stop(p); | ||
} | ||
|
||
void trace_event_listener::on_yield(std::shared_ptr<profiler> &p) { | ||
return _common_stop(p); | ||
} | ||
|
||
void trace_event_listener::on_sample_value(sample_value_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_periodic(periodic_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::on_custom_event(custom_event_data &data) { | ||
APEX_UNUSED(data); | ||
if (!_terminate) { | ||
} | ||
return; | ||
} | ||
|
||
void trace_event_listener::set_node_id(int node_id, int node_count) { | ||
APEX_UNUSED(node_id); | ||
APEX_UNUSED(node_count); | ||
} | ||
|
||
void trace_event_listener::set_metadata(const char * name, const char * value) { | ||
APEX_UNUSED(name); | ||
APEX_UNUSED(value); | ||
} | ||
|
||
std::string trace_event_listener::make_tid (uint32_t device, uint32_t context, uint32_t stream) { | ||
cuda_thread_node tmp(device, context, stream); | ||
size_t tid; | ||
if (vthread_map.count(tmp) == 0) { | ||
vthread_map.insert(std::pair<cuda_thread_node, size_t>(tmp,vthread_map.size())); | ||
} | ||
tid = vthread_map[tmp]; | ||
std::stringstream ss; | ||
ss << "GPU: " << tid; | ||
std::string label{ss.str()}; | ||
return label; | ||
} | ||
|
||
void trace_event_listener::on_async_event(uint32_t device, uint32_t context, | ||
uint32_t stream, std::shared_ptr<profiler> &p) { | ||
if (!_terminate) { | ||
_mutex.lock(); | ||
trace << "{\"name\": \"" << p->get_task_id()->get_name() | ||
<< "\", \"cat\": \"PERF\", \"ph\": \"B\", \"pid\": \"" | ||
<< saved_node_id << "\", \"tid\": " << make_tid(device, context, stream) | ||
<< ", \"ts\": \"" << p->get_start() << "\"},\n"; | ||
trace << "{\"name\": \"" << p->get_task_id()->get_name() | ||
<< "\", \"cat\": \"PERF\", \"ph\": \"E\", \"pid\": \"" << saved_node_id | ||
<< "\", \"tid\": " << make_tid(device, context, stream) | ||
<< ", \"ts\": \"" << p->get_stop() << "\"},\n"; | ||
_mutex.unlock(); | ||
} | ||
} | ||
|
||
/* This function is used by APEX threads so that TAU knows about them. */ | ||
int initialize_worker_thread_for_trace_event(void) { | ||
if (trace_event_listener::initialized()) | ||
{ | ||
} | ||
return 0; | ||
} | ||
|
||
}// end namespace | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2014 University of Oregon | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#pragma once | ||
|
||
#include "event_listener.hpp" | ||
#include <memory> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <map> | ||
|
||
namespace apex { | ||
|
||
class trace_event_listener : public event_listener { | ||
|
||
class cuda_thread_node { | ||
public: | ||
uint32_t _device; | ||
uint32_t _context; | ||
uint32_t _stream; | ||
cuda_thread_node(uint32_t device, uint32_t context, uint32_t stream) : | ||
_device(device), _context(context), _stream(stream) { } | ||
bool operator==(const cuda_thread_node &rhs) const { | ||
return (_device==rhs._device && | ||
_context==rhs._context && | ||
_stream==rhs._stream); | ||
} | ||
bool operator<(const cuda_thread_node &rhs) const { | ||
if (_device<rhs._device) { | ||
return true; | ||
} else if (_device == rhs._device && _context<rhs._context) { | ||
return true; | ||
} else if (_device == rhs._device && _context==rhs._context && _stream<rhs._stream) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
public: | ||
trace_event_listener (void); | ||
~trace_event_listener (void); | ||
static bool initialize_tau(int argc, char** avgv); | ||
inline static bool initialized(void) { return _initialized; } | ||
void on_startup(startup_event_data &data); | ||
void on_dump(dump_event_data &data); | ||
void on_reset(task_identifier * id) | ||
{ APEX_UNUSED(id); }; | ||
void on_shutdown(shutdown_event_data &data); | ||
void on_new_node(node_event_data &data); | ||
void on_new_thread(new_thread_event_data &data); | ||
void on_exit_thread(event_data &data); | ||
bool on_start(std::shared_ptr<task_wrapper> &tt_ptr); | ||
void on_stop(std::shared_ptr<profiler> &p); | ||
void on_yield(std::shared_ptr<profiler> &p); | ||
bool on_resume(std::shared_ptr<task_wrapper> &tt_ptr); | ||
void on_task_complete(std::shared_ptr<task_wrapper> &tt_ptr) { | ||
APEX_UNUSED(tt_ptr); | ||
}; | ||
void on_sample_value(sample_value_event_data &data); | ||
void on_periodic(periodic_event_data &data); | ||
void on_custom_event(custom_event_data &data); | ||
void on_send(message_event_data &data) { APEX_UNUSED(data); }; | ||
void on_recv(message_event_data &data) { APEX_UNUSED(data); }; | ||
void set_node_id(int node_id, int node_count); | ||
void set_metadata(const char * name, const char * value); | ||
void on_async_event(uint32_t device, uint32_t context, | ||
uint32_t stream, std::shared_ptr<profiler> &p); | ||
std::string make_tid (uint32_t device, uint32_t context, | ||
uint32_t stream); | ||
|
||
private: | ||
void _init(void); | ||
bool _terminate; | ||
bool _common_start(std::shared_ptr<task_wrapper> &tt_ptr); | ||
void _common_stop(std::shared_ptr<profiler> &p); | ||
static bool _initialized; | ||
std::ofstream trace; | ||
std::mutex _mutex; | ||
std::map<cuda_thread_node, size_t> vthread_map; | ||
int saved_node_id; | ||
}; | ||
|
||
int initialize_worker_thread_for_tau(void); | ||
|
||
} | ||
|
Oops, something went wrong.