Ethereum  PoC-8
The C++ Implementation of Ethereum
ImportPerformanceLogger.cpp
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 */
22 
23 #include <boost/algorithm/string.hpp>
24 #include <boost/range/adaptors.hpp>
25 
26 using namespace dev;
27 using namespace eth;
28 
29 namespace
30 {
31 
32 template <class ValueType>
33 static std::string pairToString(std::pair<std::string const, ValueType> const& _pair)
34 {
35  return "\"" + _pair.first + "\": " + toString(_pair.second);
36 }
37 
38 }
39 
40 std::string ImportPerformanceLogger::constructReport(double _totalElapsed, std::unordered_map<std::string, std::string> const& _additionalValues)
41 {
42  static std::string const Separator = ", ";
43 
44  std::string result;
45  if (!_additionalValues.empty())
46  {
47  auto const keyValuesAdditional = _additionalValues | boost::adaptors::transformed(pairToString<std::string>);
48  result += boost::algorithm::join(keyValuesAdditional, Separator);
49  result += Separator;
50  }
51 
52  m_stages.emplace("total", _totalElapsed);
53  auto const keyValuesStages = m_stages | boost::adaptors::transformed(pairToString<double>);
54  result += boost::algorithm::join(keyValuesStages, Separator);
55 
56  return result;
57 }
58 
59 
ImportPerformanceLogger.h
dev::toString
std::string toString(std::chrono::time_point< T > const &_e, std::string const &_format="%F %T")
Definition: CommonIO.h:86
dev
Definition: Address.cpp:21