SheafSystem  0.0.0.0
report.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Implementation for class stop_watch
19 
20 #include "SheafSystem/report.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/namespace_poset.h"
24 #include "SheafSystem/std_fstream.h"
25 #include "SheafSystem/std_iostream.h"
26 #include "SheafSystem/std_iomanip.h"
27 
28 using namespace std;
29 
30 // ===========================================================
31 // ANY FACET
32 // ===========================================================
33 
34 
35 
36 bool
38 invariant() const
39 {
40  bool result = true;
41 
42  invariance(watch().invariant());
43  invariance(watch().lap_ct() == names().ct());
44  invariance(name_space() != 0 ? watch().lap_ct() == memory().ct() : true);
45 
46  // Exit
47 
48  return result;
49 }
50 
51 // ===========================================================
52 // STOP_WATCH FACET
53 // ===========================================================
54 
57 {
58 
59  // Preconditions:
60 
61  // Body:
62 
63  _name_space = 0;
64  reset();
65 
66  // Postconditions:
67 
68  ensure(invariant());
69 
70  // Exit:
71 
72  return;
73 }
74 
76 report(const namespace_poset* xname_space)
77 {
78 
79  // Preconditions:
80 
81  require(xname_space != 0 ? xname_space->state_is_read_accessible() : true);
82 
83  // Body:
84 
85  _name_space = xname_space;
86  reset();
87 
88  // Postconditions:
89 
90  ensure(invariant());
91 
92  // Exit:
93 
94  return;
95 }
96 
99 {
100  // Preconditions:
101 
102  // Body:
103 
104  // Nothing to do.
105 
106  // Postconditions:
107 
108  // Exit:
109 
110  return;
111 }
112 
113 void
115 start(const std::string& xtitle)
116 {
117  // Preconditions:
118 
119  // Body:
120 
121  _title = xtitle;
122  _watch.start();
123 
124  // Postconditions:
125 
126  // Exit:
127 
128  return;
129 }
130 
131 void
134 {
135  // Preconditions:
136 
137 
138  // Body:
139 
140  _title = "";
141  _watch.reset();
142  _names.clear();
143  _memory.clear();
144  for (int i=0; i<3; i++)
145  _memory_parts[i].clear();
146 
147  // Postconditions:
148 
149  ensure(invariant());
150 
151  // Exit:
152 
153  return;
154 }
155 
156 void
158 point(const std::string& xname)
159 {
160  // Preconditions:
161 
162  // Body:
163 
164  _watch.mark_lap();
165  _names.push_back(xname);
166  size_t lmemory_parts[4];
167 
168  if(_name_space != 0)
169  {
170  _memory.push_back(deep_size(*_name_space, true, lmemory_parts));
171  for (int i=0; i<4; i++)
172  _memory_parts[i].push_back(lmemory_parts[i]);
173  }
174 
175  // Postconditions:
176 
177  ensure(invariant());
178 
179  // Exit:
180 
181  return;
182 }
183 
184 void
186 write(const std::string& xfile_name) const
187 {
188  // Preconditions:
189 
190  // Body:
191 
192  ofstream lofs(xfile_name.c_str());
193 
194  lofs << "Point,Time (sec),";
195  if(_name_space != 0)
196  {
197  lofs << "Memory (bytes),";
198  lofs << "Cover Relation Graph,";
199  lofs << "ID Spaces,";
200  lofs << "Subposets,";
201  lofs << "DOF Tuples,";
202  }
203  lofs << endl;
204 
205  for(size_t i=0; i<_watch.lap_ct(); i++)
206  {
207  lofs << _names[i] << "," << _watch.lap_time(i) << ",";
208  if(_name_space != 0)
209  {
210  lofs << _memory[i] << ",";
211  lofs << _memory_parts[0][i] << ",";
212  lofs << _memory_parts[1][i] << ",";
213  lofs << _memory_parts[2][i] << ",";
214  lofs << _memory_parts[3][i] << ",";
215  }
216  lofs << endl;
217  }
218 
219  lofs << "Total," << _watch.cumulative_time() << ",";
220  if(_name_space != 0)
221  {
222  size_t lmemory_parts[4];
223  lofs << deep_size(*_name_space, true, lmemory_parts) << ",";
224  lofs << lmemory_parts[0] << ",";
225  lofs << lmemory_parts[1] << ",";
226  lofs << lmemory_parts[2] << ",";
227  lofs << lmemory_parts[3] << ",";
228  }
229  lofs << endl;
230 
231  // Postconditions:
232 
233  // Exit:
234 
235  return;
236 }
237 
238 // ===========================================================
239 // NON-MEMBER FUNCTIONS
240 // ===========================================================
241 
242 std::ostream &
243 sheaf::
244 operator << (std::ostream &xos, report& xreport)
245 {
246  size_t lcol1 = 30;
247  size_t lcol2 = 20;
248  size_t lcol3 = 20;
249  size_t lcol4 = 24;
250  size_t lcol5 = 20;
251  size_t lcol6 = 20;
252  size_t lcol7 = 20;
253 
254  // Write report name.
255 
256  xos << "Report: " << xreport.title() << endl << endl;
257 
258  // Write table headers.
259 
260  xos << setw(lcol1) << "Point" << setw(lcol2) << "Time (sec)";
261  if(xreport.name_space() != 0)
262  {
263  xos << setw(lcol3) << "Memory (bytes)";
264  xos << setw(lcol4) << "Cover Relation Graph";
265  xos << setw(lcol5) << "ID Spaces";
266  xos << setw(lcol6) << "Subposets";
267  xos << setw(lcol7) << "DOF Tuples";
268  }
269  xos << endl;
270 
271  // Write header separator.
272 
273  size_t ltotal = lcol1 + lcol2;
274  if(xreport.name_space() != 0)
275  ltotal += lcol3 + lcol4 + lcol5 + lcol6 + lcol7;
276 
277  for(size_t i=0; i<ltotal; i++)
278  {
279  xos << "-";
280  }
281  xos << endl;
282 
283  // Write points.
284 
285  stop_watch lwatch = xreport.watch();
286 
287  for(size_t i=0; i<lwatch.lap_ct(); ++i)
288  {
289  xos << setw(lcol1) << xreport.names()[i]
290  << setw(lcol2) << lwatch.lap_time(i);
291 
292  if(xreport.name_space() != 0)
293  {
294  xos << setw(lcol3) << xreport.memory()[i];
295  xos << setw(lcol4) << xreport.memory_part(0)[i];
296  xos << setw(lcol5) << xreport.memory_part(1)[i];
297  xos << setw(lcol6) << xreport.memory_part(2)[i];
298  xos << setw(lcol7) << xreport.memory_part(3)[i];
299  }
300  xos << endl;
301  }
302 
303  // Write total.
304 
305  xos << endl;
306  xos << setw(lcol1) << "Total" << setw(lcol2) << lwatch.cumulative_time();
307  if(xreport.name_space() != 0)
308  {
309  size_t lmemory_parts[4];
310  xos << setw(lcol3) << deep_size(*xreport.name_space(), true, lmemory_parts);
311  xos << setw(lcol4) << lmemory_parts[0];
312  xos << setw(lcol5) << lmemory_parts[1];
313  xos << setw(lcol6) << lmemory_parts[2];
314  xos << setw(lcol7) << lmemory_parts[3];
315  }
316  xos << endl;
317 
318  return xos;
319 }
std::string title() const
Title of the report.
Definition: report.h:111
block< size_t > memory() const
Deep size of the namespace poset for each point.
Definition: report.h:135
void write(const std::string &xfile_name) const
Write the report to a comma separated value file.
Definition: report.cc:186
double cumulative_time() const
The accumulated time in seconds between start()&#39;s and stop()&#39;s since the last reset().
Definition: stop_watch.cc:157
block< std::string > names() const
Names of the report points.
Definition: report.h:127
double lap_time(int i) const
The length in seconds of the xi-th lap.
Definition: stop_watch.cc:197
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
size_t lap_ct() const
The number of laps that have be marked.
Definition: stop_watch.cc:221
STL namespace.
virtual bool invariant() const
Class invariant.
Definition: report.cc:38
report()
Default constructor.
Definition: report.cc:56
void point(const std::string &xname)
Mark a point named, xname, in the report.
Definition: report.cc:158
void reset()
Reset the report.
Definition: report.cc:133
virtual ~report()
Destructor.
Definition: report.cc:98
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
block< size_t > memory_part(int lpart) const
Deep size of the namespace for each component for each point.
Definition: report.h:143
A report generating class.
Definition: report.h:47
A clock for timing intervals.
Definition: stop_watch.h:45
stop_watch watch() const
Stop watch used to time the report points.
Definition: report.h:119
void start(const std::string &xname)
Starts a new report with title, xtitle.
Definition: report.cc:115
const namespace_poset * name_space() const
Namespace for the report.
Definition: report.h:103