The Battle for Wesnoth  1.17.0-dev
tracer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "tracer.hpp"
17 
18 #include <iomanip>
19 #include <iostream>
20 
22  : tracer_(t)
23 {
24 }
25 
27 {
28  if(!tracer_) {
29  return;
30  }
31 
32  std::cerr << "Run statistics for " << tracer_->function << ":\n"
33  << "Runs:\t" << std::dec << tracer_->run << "\n";
34 
35  std::size_t maximum_length = 0;
36  for(const auto& counter : tracer_->counters) {
37  maximum_length = std::max(
38  maximum_length
39  , counter.first.second.length());
40  }
41 
42  std::ios_base::fmtflags original_flag = std::cerr.setf(
44  , std::ios_base::adjustfield);
45 
46  for(const auto& counter : tracer_->counters) {
47  std::cerr << "Marker: "
48  << std::left
49  << std::setw(maximum_length) << counter.first.second
50  << std::right
51  << " [" << std::setw(5) << counter.first.first << ']'
52  << " hits " << counter.second << "\n";
53  }
54 
55  std::cerr.setf(original_flag, std::ios_base::adjustfield);
56 }
57 
58 tracer::tracer(const char* const function)
59  : run(0)
61  , counters()
62 {
63 }
const char *const function
The function being traced.
Definition: tracer.hpp:59
const tracer *const tracer_
The tracer, whose statistics to print.
Definition: tracer.hpp:47
Contains code for tracing the code.
lu_byte right
Definition: lparser.cpp:1227
int run
The total number of runs.
Definition: tracer.hpp:56
printer(const printer &)=delete
double t
Definition: astarsearch.cpp:65
lu_byte left
Definition: lparser.cpp:1226
tracer(const tracer &)=delete
Helper structure for gathering the tracing statistics.
Definition: tracer.hpp:27
std::map< std::pair< int, std::string >, int > counters
The tracer counters.
Definition: tracer.hpp:73