The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tracer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 
20 ttracer::tprint::tprint(const ttracer* const tracer__)
21  : tracer(tracer__)
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  typedef std::pair<std::pair<int, std::string>, int> thack;
35  size_t maximum_length = 0;
36  for(const thack& 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 thack& 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 ttracer::ttracer(const char* const function__)
59  : run(0)
60  , function(function__)
61  , counters()
62 {
63 }
GLuint counter
Definition: glew.h:2584
GLint GLint GLsizei GLuint * counters
Definition: glew.h:2586
Helper structure for gathering the tracing statistics.
Definition: tracer.hpp:29
const char *const function
The function being traced.
Definition: tracer.hpp:57
int run
The total number of runs.
Definition: tracer.hpp:54
ttracer(const char *const function__)
Definition: tracer.cpp:58
Contains code for tracing the code.
lu_byte right
Definition: lparser.cpp:1020
GLint left
Definition: glew.h:5907
tprint(const ttracer *const tracer__)
Definition: tracer.cpp:20