32 #ifndef _PROFILER_HHP_ 33 #define _PROFILER_HHP_ 81 Profiler() : m_CurrentSession(nullptr), m_ProfileCount(0){
87 std::stringstream filename;
89 m_OutputStream.open(filename.str().c_str());
97 m_OutputStream.close();
98 delete m_CurrentSession;
99 m_CurrentSession =
nullptr;
106 if (m_ProfileCount++ > 0)
107 m_OutputStream <<
",";
109 std::string name = result.
Name;
110 std::replace(name.begin(), name.end(),
'"',
'\'');
113 m_OutputStream <<
"{";
114 m_OutputStream <<
"\"cat\":\"function\",";
115 m_OutputStream <<
"\"dur\":" << (result.
End - result.
Start) <<
',';
116 m_OutputStream <<
"\"name\":\"" << name <<
"\",";
117 m_OutputStream <<
"\"ph\":\"X\",";
118 m_OutputStream <<
"\"pid\":\"" << result.
ThreadID <<
"\",";
119 m_OutputStream <<
"\"tid\":" <<
rank <<
",";
120 m_OutputStream <<
"\"ts\":" << result.
Start;
121 m_OutputStream <<
"}";
124 m_OutputStream.flush();
129 m_OutputStream <<
"{\"otherData\": {},\"traceEvents\":[";
130 m_OutputStream.flush();
135 m_OutputStream <<
"]}";
136 m_OutputStream.flush();
168 Timer(
const char* name) : m_Name(name), m_Stopped(false){
169 std::this_thread::sleep_for (std::chrono::microseconds(3));
170 m_StartTimepoint = std::chrono::high_resolution_clock::now();
181 auto endTimepoint = std::chrono::high_resolution_clock::now();
183 long long start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimepoint).time_since_epoch().count();
184 long long end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count();
185 int threadID = omp_get_num_threads();
203 #define PROFILE_SCOPE(name) Timer timer(name) 206 #define PROFILE_FUNCTION() PROFILE_SCOPE( __PRETTY_FUNCTION__ ) 210 #define PROFILE_FUNCTION() int rank
The processor number.
void WriteHeader()
Writes the header file for the JSON-file.
Definition: Profiler.hpp:128
std::ofstream m_OutputStream
The output JSON file where data is written.
Definition: Profiler.hpp:150
std::chrono::time_point< std::chrono::high_resolution_clock > m_StartTimepoint
Time when the timer starts.
Definition: Profiler.hpp:196
~Timer()
Destroys this timer.
Definition: Profiler.hpp:174
const char * m_Name
Name of the function to be timed.
Definition: Profiler.hpp:193
void WriteFooter()
Writes the footer file for the JSON-file.
Definition: Profiler.hpp:134
static Profiler & Get()
Gets the Profiler instance.
Definition: Profiler.hpp:140
int ThreadID
The identifier of this thread.
Definition: Profiler.hpp:57
Structure that holds profiling parameters.
Definition: Profiler.hpp:46
This file sets the global variables to be used during SeismoVLAB execution.
void EndSession()
Ends the Profiler output file.
Definition: Profiler.hpp:95
void Stop()
Stops this timer.
Definition: Profiler.hpp:180
InstrumentationSession * m_CurrentSession
The name of the function to be Profile.
Definition: Profiler.hpp:147
std::string Name
Name of the function to be profiled.
Definition: Profiler.hpp:48
Profiler()
Creates the Profiler object.
Definition: Profiler.hpp:81
void BeginSession(const std::string &name)
Starts the Profiler output file.
Definition: Profiler.hpp:86
long long End
Time when Profiler ends.
Definition: Profiler.hpp:54
Timer(const char *name)
Creates the Scope Timer.
Definition: Profiler.hpp:168
Structure that holds function name to be profile.
Definition: Profiler.hpp:61
bool m_Stopped
Whether or not the timer is stoped.
Definition: Profiler.hpp:199
void WriteProfile(const ProfileResult &result)
Starts the Profiler output file.
Definition: Profiler.hpp:105
Class that compute how long it takes for a program to be executed, and sequentially measures the time...
Definition: Profiler.hpp:163
std::string filePath
The folder path where the file is loaded.
long long Start
Time when Profiler starts.
Definition: Profiler.hpp:51
std::string Name
Name of the function to be profiled.
Definition: Profiler.hpp:63
int m_ProfileCount
Counter for array separator.
Definition: Profiler.hpp:153
Class that creates a JSON file with the time of execution of each function, files can be open at chro...
Definition: Profiler.hpp:77