TPIE

2362a60
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/portability.h>
29 #include <tpie/util.h>
31 
37 #define TPIE_FSI __FILE__,__FUNCTION__
38 
39 namespace tpie {
40 
44 void init_fraction_db(bool capture_progress = false);
45 
49 void finish_fraction_db();
50 
51 class fractional_progress;
52 
57 public:
59 
61  const char * id,
62  const char * file,
63  const char * function,
64  stream_size_type n,
65  const char * crumb=0,
66  description_importance importance=IMPORTANCE_MAJOR,
67  bool enabled=true);
68 
69  void setup(const char * id,
70  const char * file,
71  const char * function,
72  stream_size_type n,
73  const char * crumb=0,
74  description_importance importance=IMPORTANCE_MAJOR,
75  bool enabled=true);
76 
78 
82  virtual void init(stream_size_type range);
83 
87  virtual void done();
88 private:
89 #ifndef TPIE_NDEBUG
90  bool m_init_called;
91  bool m_done_called;
92 #endif
93  double m_fraction;
94  stream_size_type m_estimate;
95  double m_confidence;
96  stream_size_type m_n;
97  fractional_progress & m_fp;
98  execution_time_predictor m_predict;
99 
100  std::string m_stat;
101  friend class fractional_progress;
102 };
103 
108 public:
111 
115  void done();
116 
120  void init(stream_size_type range=0);
121 
125  unique_id_type & id();
126 
127  void push_breadcrumb(const char * crumb, description_importance importance) {
128  if (m_pi) m_pi->push_breadcrumb(crumb, importance);
129  }
130 
131  void pop_breadcrumb() {
132  if (m_pi) m_pi->pop_breadcrumb();
133  }
134 
135 private:
136  double get_fraction(fractional_subindicator & sub);
137 
138  void add_sub_indicator(fractional_subindicator & sub);
140  bool m_add_state;
141 #ifndef TPIE_NDEBUG
142  bool m_init_called;
143  bool m_done_called;
144 #endif
145  double m_confidence;
146 
147  unique_id_type m_id;
148  double m_total_sum;
149  stream_size_type m_time_sum;
150 
151  void stat(std::string, time_type, stream_size_type);
152  std::vector< std::pair<std::string, std::pair<time_type, stream_size_type> > > m_stat;
153 
154  std::string sub_indicators_ss();
155 
156  friend class fractional_subindicator;
157 };
158 
159 void update_fractions(const char * name, float frac, stream_size_type n);
160 void load_fractions(const std::string & path);
161 void save_fractions(const std::string & path, bool force = false);
162 
163 }
164 #endif //__TPIE_FRACTIONAL_PROGRESS__
165 
The base class for indicating the progress of some task.
unique_id_type & id()
Return this progress indicator's unique id.
Central file abstraction.
Definition: file.h:44
Fractional progress reporter.
This file contains a few deprecated definitions for legacy code.
void init_fraction_db(bool capture_progress=false)
Used by tpie_init to initialize the fraction database.
void finish_fraction_db()
Used by tpie_finish to deinitialize the fraction database.
void done()
Advance the indicator to the end.
void init(stream_size_type range=0)
Initialize progress indicator.
virtual void init(stream_size_type range)
Initialize progress indicator.
Miscellaneous utility functions.
virtual void done()
Advance the indicator to the end.
Indicate progress of a part of a computation.
Subindicator for fractional progress reporting.