33#include < chrono>
44#include " chimbuko/util/commandLineParser.hpp"
55#include " chimbuko/util/string.hpp"
6+ #include " chimbuko/util/error.hpp"
67
78using namespace chimbuko ;
89using namespace std ::chrono;
910
1011struct SinkerArgs {
1112 int timeout;
1213 int beginstep_timeout;
13-
14- SinkerArgs (): timeout(60 ), beginstep_timeout(30 ){}
14+ bool dump_events;
15+
16+ SinkerArgs (): timeout(60 ), beginstep_timeout(30 ), dump_events(false ){}
1517};
1618
19+ void dumpEvents (std::ostream &os, const std::vector<Event_t> &events, ADParser* parser){
20+ const std::unordered_map<int , std::string> &func_map = *parser->getFuncMap ();
21+ const std::unordered_map<int , std::string> &counter_map = *parser->getCounterMap ();
22+ const std::unordered_map<int , std::string> &event_type_map = *parser->getEventType ();
23+
24+ for (const Event_t &e: events){
25+ if (e.type () == EventDataType::FUNC){
26+ auto eit = event_type_map.find (e.eid ()); if (eit == event_type_map.end ()) fatal_error (" Could not find event type in map!" );
27+ const std::string &etype = eit->second ;
28+ auto fit = func_map.find (e.fid ()); if (fit == func_map.end ()) fatal_error (" Could not find fid in map!" );
29+ os << e.tid () << " " << e.ts () << " FUNC " << etype << " " << fit->second << std::endl;
30+ }else if (e.type () == EventDataType::COUNT){
31+ auto cit = counter_map.find (e.counter_id ()); if (cit == counter_map.end ()) fatal_error (" Could not find counter id in map!" );
32+ os << e.tid () << " " << e.ts () << " COUNT " << cit->second << " " << e.counter_value () << std::endl;
33+ }else if (e.type () == EventDataType::COMM){
34+ os << e.tid () << " " << e.ts () << " COMM " << e.partner () << " " << e.bytes () << std::endl;
35+ }
36+ }
37+ }
38+
1739
1840int main (int argc, char ** argv){
1941 MPI_Init (&argc, &argv);
@@ -28,9 +50,10 @@ int main(int argc, char ** argv){
2850 commandLineParser<SinkerArgs> cmdline;
2951 addOptionalCommandLineArg (cmdline, timeout, " Specify the SST connect timeout in seconds (Default 60s)" );
3052 addOptionalCommandLineArg (cmdline, beginstep_timeout, " Specify the SST beginStep timeout in seconds (Default 30s)" );
31-
53+ addOptionalCommandLineArg (cmdline, dump_events, " Request that the parsed events be dumped to a file \" ${BPFILENAME}.dump\" . Requires \" fetch\" to be true. (Default false)" );
54+
3255 if (argc < 5 || (argc == 2 && std::string (argv[1 ]) == " -help" )){
33- std::cout << " Usage: <exe> <engine type (BPFile, SST)> <bp directory> <bpfile prefix (eg tau-metrics-nwchem)> <fetch>\n "
56+ std::cout << " Usage: <exe> <engine type (BPFile, SST)> <bp directory> <bpfile prefix (eg tau-metrics-nwchem)> <fetch> <options> \n "
3457 << " Where \" fetch\" indicates whether the data is actually transferred or we just iterate over the IO steps\n "
3558 << " Options:" << std::endl;
3659 cmdline.help (std::cout);
@@ -46,6 +69,8 @@ int main(int argc, char ** argv){
4669 SinkerArgs args;
4770 cmdline.parse (args, argc-5 , (const char **)(argv+5 ) );
4871
72+ if (args.dump_events && !fetch_data) fatal_error (" dump_events option requires fetch=1" );
73+
4974 if (world_rank == 0 ) {
5075 std::cout << " \n "
5176 << " rank : " << world_rank << " \n "
@@ -79,6 +104,10 @@ int main(int argc, char ** argv){
79104
80105 parser->setBeginStepTimeout (args.beginstep_timeout );
81106
107+ // Initialize dump output
108+ std::ofstream *dump = nullptr ;
109+ if (args.dump_events ) dump = new std::ofstream (inputFile + " .dump" );
110+
82111 // -----------------------------------------------------------------------
83112 // Start analysis
84113 // -----------------------------------------------------------------------
@@ -102,6 +131,9 @@ int main(int argc, char ** argv){
102131 parser->fetchFuncData ();
103132 parser->fetchCommData ();
104133 parser->fetchCounterData ();
134+
135+ if (args.dump_events )
136+ dumpEvents (*dump, parser->getEvents (),parser);
105137 }
106138
107139 frames++;
@@ -140,6 +172,7 @@ int main(int argc, char ** argv){
140172 // Finalize
141173 // -----------------------------------------------------------------------
142174 delete parser;
175+ if (dump) delete dump;
143176 }
144177 catch (std::invalid_argument &e)
145178 {
0 commit comments