Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
prof.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief
12 /// @author
13 
14 #ifndef INCLUDED_basic_prof_hh
15 #define INCLUDED_basic_prof_hh
16 
17 #include <basic/Tracer.fwd.hh>
18 #include <time.h> // for clock
19 #include <basic/options/keys/run.OptionKeys.gen.hh> // for profile
20 #include <basic/options/option.hh> // for OptionCollection
21 #include <iosfwd> // for string
22 #include <string> // for allocator
23 #include <utility/options/BooleanOption.hh> // for BooleanOption
24 #include <utility/vector1.hh> // for vector1
25 #include <utility/vectorL.hh> // for vectorL
26 
27 
28 namespace basic {
29 /**
30 not intended for profiling inside tight loops
31 the clock() routine currently being used has fairly crappy
32 resolution and it will introduce some small overhead with the
33 function calls and the if-check even if not using -profile on
34 the command line
35 
36 you can wrap it around large-ish chunks of code, like fullatom_energy
37 or rotamer_trials...
38 
39 A simple setup for timing code fragments. Probably not optimal timing
40 functions -- I'm open to suggestions.
41 
42 looks like (see eg fullatom_energy or scorefxn)
43 
44 PROF_START( prof::TAG );
45 
46 <function call>
47 
48 PROF_STOP( prof::TAG );
49 
50 where TAG is in the enum "Prof_tag" below (feel free to add new ones)
51 also add to tag2string if you want friendly output.
52 
53 PROF_STOP checks the time and increments the total time assigned to TAG
54 
55 
56 2. later on, in your simulation code you can do:
57 
58 prof_reset();
59 
60 -- miscellaneous simulation --
61 
62 prof_show();
63 
64 The final call to prof::show() will display the time usage measured
65 by all the PROF_* calls between reset() and show()
66 **/
67 
68 #ifdef NO_PROF
69 #define PROF_START(expr)
70 #define PROF_STOP(expr)
71 #else
72 #define PROF_START(expr) ( prof_start_function_body( expr) )
73 #define PROF_STOP(expr) ( prof_stop_function_body( expr ) )
74 #endif
75 
76 enum ProfTag {
77  TEST1 = 1,
92 
108 
111 
113 
118 
149  RG,
179 
191 
202 
206 
232 
259 
296  // NOESY_ASSIGN_DIST_,
300 
301  TOTAL, // keep these two last
303 };
304 
305 
311 
312 extern double const clock_factor;
313 extern clock_t const SHRINK_FACTOR; // prevent overflow
314 
315 inline
316 void
318 {
319  using namespace basic::options;
320  using namespace basic::options::OptionKeys;
321 
322  // don't profile unless instructed to via the option -run:profile
323  if ( !option[basic::options::OptionKeys::run::profile] ) {
324  return;
325  }
326 
327  start_clock[ tag ] = clock() / SHRINK_FACTOR;
328  ++calls[ tag ];
329 }
330 
331 
332 inline
333 void
335 {
336  using namespace basic::options;
337  using namespace basic::options::OptionKeys;
338 
339  // don't profile unless instructed to via the option -run:profile
340  if ( !option[basic::options::OptionKeys::run::profile] ) {
341  return;
342  }
343 
344  clock_t const current( clock() / SHRINK_FACTOR );
345  clock_t const start( start_clock[tag] );
346 
347  if ( current >= start ) {
348  total_clock[ tag ] += clock_factor * ( current - start );
349  } else {
350  --calls[ tag ];
351  ++bad_calls[ tag ];
352  }
353 }
354 
355 void prof_reset();
356 
357 void prof_show();
358 
359 class ProfileThis {
360 public:
361  ProfileThis( ProfTag tag ) : tag_( tag ) {
362  PROF_START( tag_ );
363  }
365  PROF_STOP( tag_ );
366  }
367 private:
369 };
370 
372 public:
373  DynamicProfileThis( std::string const& prof_tag );
375 private:
376  clock_t start_clock_;
377  std::string tag_;
378 };
379 
380 /// @brief print "TIME_STAMP: Www Mmm dd hh:mm:ss yyyy msg" on tr.Error and on std::cerr (if boolean is true)
381 extern bool show_time_on_cerr;
382 void show_time( basic::Tracer& tr, std::string const& msg );
383 
384 } // basic
385 
386 #endif
utility::vector1< clock_t > start_clock(n_prof_tags, 0)
Definition: prof.hh:307
Program boolean option class.
#define PROF_STOP(expr)
Definition: prof.hh:73
bool show_time_on_cerr
print "TIME_STAMP: Www Mmm dd hh:mm:ss yyyy msg" on tr.Error and on std::cerr (if boolean is true) ...
clock_t const SHRINK_FACTOR
utility::vector1< int > calls(n_prof_tags, 0)
Definition: prof.hh:309
double const clock_factor
vectorL: std::vector with L-based indexing
void show_time(basic::Tracer &tr, std::string const &msg)
Definition: prof.cc:44
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
void prof_reset()
Definition: prof.cc:382
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
std::string tag_
Definition: prof.hh:377
utility::vector1< int > bad_calls(n_prof_tags, 0)
Definition: prof.hh:310
ProfileThis(ProfTag tag)
Definition: prof.hh:361
ProfTag
Definition: prof.hh:76
void prof_stop_function_body(ProfTag const tag)
Definition: prof.hh:334
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
ProfTag tag_
Definition: prof.hh:368
void prof_start_function_body(ProfTag const tag)
Definition: prof.hh:317
Program options global and initialization function.
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373
THREAD_LOCAL basic::Tracer tr("struc_set_fragment_picker")
#define PROF_START(expr)
Definition: prof.hh:72
utility::vector1< double > total_clock(n_prof_tags, 0)
Definition: prof.hh:308
utility::vector1< std::string > tag2string
Definition: prof.cc:32
void prof_show()
Definition: prof.cc:326