TPIE

11a2c2d
fractional_progress.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2008, 2012, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser 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 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
24 
25 #ifndef __TPIE_FRACTIONAL_PROGRESS__
26 #define __TPIE_FRACTIONAL_PROGRESS__
27 
28 #include <tpie/tpie_export.h>
29 #include <tpie/portability.h>
30 #include <tpie/util.h>
32 
38 #define TPIE_FSI __FILE__,__FUNCTION__
39 
40 namespace tpie {
41 
45 void init_fraction_db(bool capture_progress = false);
46 
50 void finish_fraction_db();
51 
52 class fractional_progress;
53 
58 public:
60 
62  const char * id,
63  const char * file,
64  const char * function,
65  stream_size_type n,
66  const char * crumb=0,
67  description_importance importance=IMPORTANCE_MAJOR,
68  bool enabled=true);
69 
70  void setup(const char * id,
71  const char * file,
72  const char * function,
73  stream_size_type n,
74  const char * crumb=0,
75  description_importance importance=IMPORTANCE_MAJOR,
76  bool enabled=true);
77 
79 
83  virtual void init(stream_size_type range);
84 
88  virtual void done();
89 private:
90 #ifndef TPIE_NDEBUG
91  bool m_init_called;
92  bool m_done_called;
93 #endif
94  double m_fraction;
95  stream_size_type m_estimate;
96  double m_confidence;
97  stream_size_type m_n;
98  fractional_progress & m_fp;
99  execution_time_predictor m_predict;
100 
101  std::string m_stat;
102  friend class fractional_progress;
103 };
104 
108 class TPIE_EXPORT fractional_progress {
109 public:
112 
116  void done();
117 
121  void init(stream_size_type range=0);
122 
126  unique_id_type & id();
127 
128  void push_breadcrumb(const char * crumb, description_importance importance) {
129  if (m_pi) m_pi->push_breadcrumb(crumb, importance);
130  }
131 
132  void pop_breadcrumb() {
133  if (m_pi) m_pi->pop_breadcrumb();
134  }
135 
136 private:
137  double get_fraction(fractional_subindicator & sub);
138 
139  void add_sub_indicator(fractional_subindicator & sub);
141  bool m_add_state;
142 #ifndef TPIE_NDEBUG
143  bool m_init_called;
144  bool m_done_called;
145 #endif
146  double m_confidence;
147 
148  unique_id_type m_id;
149  double m_total_sum;
150  stream_size_type m_time_sum;
151 
152  void stat(std::string, time_type, stream_size_type);
153  std::vector< std::pair<std::string, std::pair<time_type, stream_size_type> > > m_stat;
154 
155  std::string sub_indicators_ss();
156 
157  friend class fractional_subindicator;
158 };
159 
160 TPIE_EXPORT void update_fractions(const char * name, float frac, stream_size_type n);
161 TPIE_EXPORT void load_fractions(const std::string & path);
162 TPIE_EXPORT void save_fractions(const std::string & path, bool force = false);
163 
164 }
165 #endif //__TPIE_FRACTIONAL_PROGRESS__
166 
tpie::progress_indicator_base
The base class for indicating the progress of some task.
Definition: progress_indicator_base.h:62
tpie::file
Central file abstraction.
Definition: file.h:39
portability.h
tpie::unique_id_type
Definition: execution_time_predictor.h:49
tpie::finish_fraction_db
void finish_fraction_db()
Used by tpie_finish to deinitialize the fraction database.
tpie::init_fraction_db
void init_fraction_db(bool capture_progress=false)
Used by tpie_init to initialize the fraction database.
tpie::progress_indicator_subindicator
Definition: progress_indicator_subindicator.h:42
tpie::fractional_subindicator
Subindicator for fractional progress reporting.
Definition: fractional_progress.h:57
tpie::execution_time_predictor
Definition: execution_time_predictor.h:66
tpie::fractional_progress
Fractional progress reporter.
Definition: fractional_progress.h:108
util.h
tpie
Definition: access_type.h:26
progress_indicator_subindicator.h