ManaPlus
perfomance.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UTILS_PERFOMANCE_H
23 #define UTILS_PERFOMANCE_H
24 
25 #ifdef USE_PROFILER
26 #include "utils/vector.h"
27 
28 #include <string>
29 #include <sstream>
30 #include <list>
31 #include <set>
32 
33 #include "localconsts.h"
34 
35 #define PROFILER_START() Perfomance::start();
36 #define PROFILER_END() Perfomance::flush();
37 #define BLOCK_START(name) Perfomance::blockStart(name);
38 #define BLOCK_END(name) Perfomance::blockEnd(name);
39 #define FUNC_BLOCK(name, id) Perfomance::Func PerfomanceFunc##id(name);
40 
41 namespace Perfomance
42 {
43  void start();
44 
45  void init(const std::string &path);
46 
47  void clear();
48 
49  void blockStart(const std::string &name);
50 
51  void blockEnd(const std::string &name);
52 
53  void flush();
54 
55  class Func final
56  {
57  public:
58  explicit Func(const std::string &str) :
59  name(str)
60  {
61  blockStart(str);
62  }
63 
64  A_DELETE_COPY(Func)
65 
66  ~Func()
67  {
68  blockEnd(name);
69  }
70 
71  std::string name;
72  };
73 } // namespace Perfomance
74 
75 #else // USE_PROFILER
76 
77 #define PROFILER_START()
78 #define PROFILER_END()
79 #define BLOCK_START(name)
80 #define BLOCK_END(name)
81 #define FUNC_BLOCK(name, id)
82 
83 #endif // USE_PROFILER
84 #endif // UTILS_PERFOMANCE_H
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
void init()
Definition: playerinfo.cpp:434
void clear()
Definition: playerinfo.cpp:452