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