Ethereum  PoC-8
The C++ Implementation of Ethereum
ImportPerformanceLogger.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
21 #pragma once
22 
23 #include <libdevcore/Common.h>
24 #include <libdevcore/Log.h>
25 
26 #include <unordered_map>
27 #include <string>
28 
29 namespace dev
30 {
31 
32 namespace eth
33 {
34 
36 {
37 public:
38  void onStageFinished(std::string const& _name)
39  {
40  m_stages[_name] = m_stageTimer.elapsed();
41  m_stageTimer.restart();
42  }
43 
44  double stageDuration(std::string const& _name) const
45  {
46  auto const it = m_stages.find(_name);
47  return it != m_stages.end() ? it->second : 0;
48  }
49 
50  void onFinished(std::unordered_map<std::string, std::string> const& _additionalValues)
51  {
52  double const totalElapsed = m_totalTimer.elapsed();
53  if (totalElapsed > 0.5)
54  {
55  cdebug << "SLOW IMPORT: { " << constructReport(totalElapsed, _additionalValues) << " }";
56  }
57  }
58 
59 private:
60  std::string constructReport(double _totalElapsed, std::unordered_map<std::string, std::string> const& _additionalValues);
61 
62  Timer m_totalTimer;
63  Timer m_stageTimer;
64  std::unordered_map<std::string, double> m_stages;
65 };
66 
67 }
68 }
dev::eth::ImportPerformanceLogger::onFinished
void onFinished(std::unordered_map< std::string, std::string > const &_additionalValues)
Definition: ImportPerformanceLogger.h:50
dev::Timer
Definition: Common.h:256
dev::Timer::elapsed
double elapsed() const
Definition: Common.h:261
Common.h
dev::eth::ImportPerformanceLogger::stageDuration
double stageDuration(std::string const &_name) const
Definition: ImportPerformanceLogger.h:44
cdebug
#define cdebug
dev::eth::ImportPerformanceLogger
Definition: ImportPerformanceLogger.h:36
dev::Timer::restart
void restart()
Definition: Common.h:262
dev
Definition: Address.cpp:21
dev::eth::ImportPerformanceLogger::onStageFinished
void onStageFinished(std::string const &_name)
Definition: ImportPerformanceLogger.h:38
Log.h