Loading [MathJax]/extensions/tex2jax.js
MAIA bb96820c
Multiphysics at AIA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Profile Class Reference

This class collects all function timings and produces a profiling for certain areas of the code. More...

#include <timer.h>

Collaboration diagram for Profile:
[legend]

Public Member Functions

 Profile (const std::string &name)
 
 ~Profile ()
 

Static Public Member Functions

static MInt getTimingId (std::string name)
 
static MString printTime (MFloat secs)
 

Static Public Attributes

static std::vector< FunctionTimings_functionTimings
 

Private Attributes

const MFloat m_initCpuTime
 
const MFloat m_initWallTime
 
const MString m_name
 

Detailed Description

Author
Lennart Schneiders
Date
14.02.2013

Definition at line 679 of file timer.h.

Constructor & Destructor Documentation

◆ Profile()

Profile::Profile ( const std::string &  name)
inlineexplicit

Definition at line 681 of file timer.h.

const MFloat m_initWallTime
Definition: timer.h:689
const MString m_name
Definition: timer.h:690
const MFloat m_initCpuTime
Definition: timer.h:688
MFloat cpuTime()
Return the process cpu time (user time) (high-resolution timer - do not use clock())
Definition: functions.h:73
MFloat wallTime()
Definition: functions.h:80

◆ ~Profile()

Profile::~Profile ( )

Definition at line 32 of file timer.cpp.

32 {
33#ifdef _OPENMP
34 if(omp_get_max_threads() > 1) {
35 m_log << "Skipping profile output for OpenMP. FIXME: Tracer not thread-safe!" << std::endl;
36 return;
37 }
38#endif
39
40 const MFloat exitCpuTime = cpuTime();
41 const MFloat exitWallTime = wallTime();
42 const MFloat thresholdPercentage = 0.5;
43 stringstream sstream;
44 sstream << " CPU WALL FUNCTION >> profile: '" << m_name << "' <<";
45 const string header = sstream.str();
46 const MString dashes1(header.size(), '_');
47 const MString dashes2(header.size(), '-');
48 m_log << dashes1 << endl << header << endl << dashes2 << endl << endl;
49
50 MInt counter = 0;
51 MInt supCounter = 0;
52 // TODO labels:TIMERS add mode to compute statistics over all ranks
53 if(s_functionTimings.size() > 0) {
54 sort(s_functionTimings.begin(), s_functionTimings.end());
56 for(vector<FunctionTiming>::size_type i = 0; i < s_functionTimings.size(); i++) {
57 if(s_functionTimings[i].getInitCpuTime() < m_initCpuTime) continue;
58 const MFloat relCpuTime =
59 100.0 * s_functionTimings[i].getDeltaCpuTime() / max(1e-15, (exitCpuTime - m_initCpuTime));
60 const MFloat relWallTime =
61 100.0 * s_functionTimings[i].getDeltaWallTime() / max(1e-15, (exitWallTime - m_initWallTime));
62 if(relCpuTime < thresholdPercentage) {
63 supCounter++;
64 continue;
65 }
66 char buffer[7];
67 sprintf(buffer, "%6.2f", relCpuTime);
68 char buffer2[7];
69 sprintf(buffer2, "%6.2f", relWallTime);
70 // TODO labels:TIMERS abbreviate function names/remove templates etc
71 m_log << buffer << "% " << buffer2 << "% " << s_functionTimings[i].getName() << endl;
72 counter++;
73 }
74 if(supCounter > 0) {
75 m_log << " ..... ..... (" << supCounter << " shorter timings with CPU<" << thresholdPercentage
76 << "% were suppressed)" << endl;
77 }
78 }
79 if(counter == 0) {
80 m_log << "No timings recorded for timer '" << m_name << "'." << endl;
81 }
82 m_log << dashes2 << endl;
83 m_log << "Total cpu time: " << printTime(exitCpuTime - m_initCpuTime) << endl;
84 m_log << "Total wall time: " << printTime(exitWallTime - m_initWallTime) << endl;
85 m_log << dashes1 << endl;
86}
static MString printTime(MFloat secs)
Definition: timer.cpp:106
static std::vector< FunctionTiming > s_functionTimings
Definition: timer.h:685
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
InfoOutFile m_log
Definition: timer.h:34

Member Function Documentation

◆ getTimingId()

MInt Profile::getTimingId ( std::string  name)
static

Definition at line 88 of file timer.cpp.

88 {
89 MInt tId = -1;
90 if(s_functionTimings.size() > 0) {
91 for(vector<FunctionTiming>::size_type i = 0; i < s_functionTimings.size(); i++) {
92 if(s_functionTimings[i].getName() == name) {
93 tId = i;
94 break;
95 }
96 }
97 }
98 if(tId < 0) {
99 tId = static_cast<MInt>(s_functionTimings.size());
100 s_functionTimings.push_back(FunctionTiming(name));
101 }
102 ASSERT(tId > -1, "Non-existing timer");
103 return tId;
104}
This class counts the static execution time of a function.
Definition: timer.h:649

◆ printTime()

MString Profile::printTime ( MFloat  secs)
static

Definition at line 106 of file timer.cpp.

106 {
107 stringstream time;
108 time.str("");
109 MFloat rem = secs;
110 if(rem > 86400.0) {
111 const MFloat div = floor(rem / 86400.0);
112 time << ((MInt)div) << " days, ";
113 rem -= div * 86400.0;
114 }
115 if(rem > 3600.0) {
116 const MFloat div = floor(rem / 3600.0);
117 time << ((MInt)div) << " hours, ";
118 rem -= div * 3600.0;
119 }
120 if(rem > 60.0) {
121 const MFloat div = floor(rem / 60.0);
122 time << ((MInt)div) << " mins, ";
123 rem -= div * 60.0;
124 }
125 time << rem << " secs";
126 const MString ret = time.str();
127 return ret;
128}

Member Data Documentation

◆ m_initCpuTime

const MFloat Profile::m_initCpuTime
private

Definition at line 688 of file timer.h.

◆ m_initWallTime

const MFloat Profile::m_initWallTime
private

Definition at line 689 of file timer.h.

◆ m_name

const MString Profile::m_name
private

Definition at line 690 of file timer.h.

◆ s_functionTimings

vector< FunctionTiming > Profile::s_functionTimings
static

Definition at line 685 of file timer.h.


The documentation for this class was generated from the following files: