www.cemf.ir
Timer.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #include "Timer.hpp"
22 #include "Timers.hpp"
23 #include "streams.hpp"
24 
26 {
27  return 0.0;
28 }
29 
31 {
32  return 0.0;
33 }
34 
35 pFlow::Timer::Timer(const word &name, Timers *parrent)
36  : name_(name),
37  parrent_(parrent)
38 {
39  if (parrent_)
40  parrent_->addToList(this);
41 }
42 
44 {
45  if (parrent_)
46  {
47  parrent_->removeFromList(this);
48  }
49 }
50 
52 {
53  if (parrent_)
54  return parrent_->level() + 1;
55  else
56  return 0;
57 }
58 
59 bool pFlow::Timer::write(iOstream& os, bool subTree) const
60 {
61  if (!timerActive() && !master())
62  return true;
63 
64  int32 lvl = level();
65  for (int32 l = 1; l < lvl; l++)
66  {
67  os << "┃ ";
68  }
69 
70  if (lvl > 0)
71  {
72  if (master())
73  os << "┣━━ ";
74  else if (lvl == 1)
75  os << "┃└─ ";
76  else
77  os << " └─ ";
78  }
79  else
80  ; // os<<"⊿ ";
81 
82  if (lvl == 0)
83  os << greenColor << boldChar;
84  else if (master())
85  os << yellowColor;
86 
87  os << name_;
88 
89  auto tt = accTimersTotal();
90  if (abs(tt) > smallValue)
91  {
92  os << " execution time (s): total (" << tt << ")";
93 
94  if (!master())
95  {
96  os << ", av. (" << averageTime() << ").";
97  }
98  }
99 
100  os << defaultColor;
101  os << '\n';
102 
103  return true;
104 }
pFlow::Timers::addToList
void addToList(Timer *timer)
Definition: Timers.hpp:77
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:31
pFlow::Timer::accTimersTotalMax
real accTimersTotalMax() const
Definition: Timer.cpp:30
pFlow::Timer::write
virtual bool write(iOstream &os, bool subTree) const
Definition: Timer.cpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::Timers
Definition: Timers.hpp:32
boldChar
const char * boldChar
Definition: iOstream.hpp:37
pFlow::Timer::parrent_
Timers * parrent_
parrent of timer
Definition: Timer.hpp:59
pFlow::Timer::~Timer
virtual ~Timer()
Definition: Timer.cpp:43
pFlow::Timer::Timer
Timer()=default
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
defaultColor
const char * defaultColor
char constants to alter output format and color
Definition: iOstream.hpp:27
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::Timer::level
virtual int32 level() const
Definition: Timer.cpp:51
streams.hpp
Timers.hpp
Timer.hpp
yellowColor
const char * yellowColor
Definition: iOstream.hpp:31
pFlow::Timer::averageTimeMax
real averageTimeMax() const
Definition: Timer.cpp:25
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
greenColor
const char * greenColor
Definition: iOstream.hpp:30