1 /* Weight_Profiler class implementation.
2 Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3 Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4
5 This file is part of the Parma Polyhedra Library (PPL).
6
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23
24 #include "ppl-config.h"
25 #include "globals_defs.hh"
26
27 #if PPL_PROFILE_ADD_WEIGHT
28 #include <iostream>
29 #include <cmath>
30 #include "Weight_Profiler_defs.hh"
31
32 namespace Parma_Polyhedra_Library {
33
output_stats()34 void Weight_Profiler::output_stats() {
35 std::cout << file << ":" << line << ": Weight_Profiler ";
36 if (stat[VALID].samples == 0 && stat[DISCARDED].samples == 0) {
37 std::cout << "never reached.";
38 }
39 else {
40 if (stat[VALID].samples > 0) {
41 double average
42 = stat[VALID].sum / stat[VALID].count;
43 double variance
44 = stat[VALID].squares_sum / stat[VALID].count - average * average;
45 std::cout << " samples(" << stat[VALID].samples << ")"
46 << " count(" << stat[VALID].count << ")"
47 << " min( " << stat[VALID].min << ")"
48 << " max( " << stat[VALID].max << ")"
49 << " average(" << average << ")";
50 std::cout << " variance( " << variance << ")"
51 << " stddev( " << sqrt(variance) << ")";
52 }
53 if (stat[DISCARDED].samples > 0) {
54 std::cout << " min_threshold( " << min_threshold << ")"
55 << " max_threshold( " << max_threshold << ")";
56 double average = stat[DISCARDED].sum / stat[DISCARDED].count;
57 std::cout << " samples(" << stat[DISCARDED].samples << ")"
58 << " count(" << stat[DISCARDED].count << ")"
59 << " min( " << stat[DISCARDED].min << ")"
60 << " max( " << stat[DISCARDED].max << ")"
61 << " average(" << average << ")";
62 }
63 }
64 std::cout << std::endl;
65 }
66
tune_adjustment()67 double Weight_Profiler::tune_adjustment() {
68 begin();
69 adjustment = 0;
70 static Weight_Profiler weight_profiler(__FILE__, __LINE__, 0, 0, 0);
71 for (int i = 0; i < 1000; ++i) {
72 weight_profiler.end(1);
73 }
74 return weight_profiler.stat[VALID].min;
75 }
76
77 struct timespec Weight_Profiler::stamp;
78 double Weight_Profiler::adjustment = Weight_Profiler::tune_adjustment();
79
80 } // namespace Parma_Polyhedra_Library
81
82 #endif
83