Skip to content
Snippets Groups Projects
Commit 54d71cf1 authored by René Fritze's avatar René Fritze
Browse files

Profiler: new scopedTiming class

parent 71d4a578
No related branches found
No related tags found
No related merge requests found
...@@ -126,6 +126,22 @@ public: ...@@ -126,6 +126,22 @@ public:
m_cur_run_num++; m_cur_run_num++;
} }
class ScopedTiming
{
const std::string section_name_;
public:
ScopedTiming(const std::string& section_name)
: section_name_(section_name)
{
Profiler::instance().StartTiming(section_name_);
}
~ScopedTiming()
{
Profiler::instance().StopTiming(section_name_);
}
};
protected: protected:
MapVector m_timings; MapVector m_timings;
unsigned int m_cur_run_num; unsigned int m_cur_run_num;
...@@ -133,6 +149,12 @@ protected: ...@@ -133,6 +149,12 @@ protected:
// debug counter, only outputted in debug mode // debug counter, only outputted in debug mode
std::map<int, int> m_count; std::map<int, int> m_count;
clock_t init_time_; clock_t init_time_;
static Profiler& instance()
{
static Profiler pf;
return pf;
}
}; };
template <class CollectiveCommunication> template <class CollectiveCommunication>
...@@ -234,7 +256,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in ...@@ -234,7 +256,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in
<< "numDofs\t" << "numDofs\t"
<< "L2 error\t"; << "L2 error\t";
for (DataMap::const_iterator it = m_timings[0].begin(); it != m_timings[0].end(); ++it) { for (DataMap::const_iterator it = m_timings[0].begin(); it != m_timings[0].end(); ++it) {
csv << it->first << ","; csv << it->first << "\t";
} }
csv << "Relative total time" << std::endl; csv << "Relative total time" << std::endl;
...@@ -267,8 +289,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in ...@@ -267,8 +289,7 @@ long Profiler::OutputCommon(CollectiveCommunication& comm, InfoContainer& run_in
//! global profiler object //! global profiler object
Profiler& profiler() Profiler& profiler()
{ {
static Profiler pf; return Profiler::instance();
return pf;
} }
#endif // PROFILER_HH_INCLUDED #endif // PROFILER_HH_INCLUDED
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment