~ubuntu-branches/ubuntu/oneiric/mpqc/oneiric

« back to all changes in this revision

Viewing changes to src/lib/util/misc/regtime.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2005-11-27 11:41:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051127114149-zgz9r3gk50w8ww2q
Tags: 2.3.0-1
* New upstream release.
* debian/rules (SONAME): Activate awk snippet for automatic so-name
  detection again, resulting in a bump to `7' and making a `c2a' for
  the C++ allocator change unnecessary; closes: #339232.
* debian/patches/00list (08_gcc-4.0_fixes): Removed, no longer needed.
* debian/rules (test): Remove workarounds, do not abort build if tests
  fail.
* debian/ref: Removed.
* debian/control.in (libsc): Added Conflict against libsc6c2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#  include <scconfig.h>
34
34
#endif
35
35
 
 
36
#include <stdexcept>
 
37
 
36
38
#include <math.h>
37
39
#include <iostream>
38
40
#include <iomanip>
85
87
#include <util/keyval/keyval.h>
86
88
#include <util/misc/regtime.h>
87
89
#include <util/misc/timer.h>
 
90
#include <util/class/scexception.h>
88
91
 
89
92
using namespace std;
90
93
using namespace sc;
91
94
 
92
95
namespace sc {
93
96
 
94
 
class TimedRegion {
95
 
  private:
96
 
    char *name_;
97
 
    TimedRegion *up_;
98
 
    TimedRegion *subregions_;
99
 
    TimedRegion *next_;
100
 
    TimedRegion *prev_;
101
 
    double cpu_time_;
102
 
    double wall_time_;
103
 
    double cpu_enter_;
104
 
    double wall_enter_;
105
 
    double flops_;
106
 
    double flops_enter_;
107
 
 
108
 
    TimedRegion *insert_after(const char *name);
109
 
    TimedRegion *insert_before(const char *name);
110
 
  public:
111
 
    TimedRegion(const char *name);
112
 
    ~TimedRegion();
113
 
    const char *name() const { return name_; }
114
 
    TimedRegion *findinsubregion(const char *);
115
 
    void cpu_enter(double);
116
 
    void wall_enter(double);
117
 
    void flops_enter(double);
118
 
    void cpu_exit(double);
119
 
    void wall_exit(double);
120
 
    void flops_exit(double);
121
 
    void cpu_add(double t) { cpu_time_ += t; }
122
 
    void wall_add(double t) { wall_time_ += t; }
123
 
    void flops_add(double t) { flops_ += t; }
124
 
    TimedRegion *up() const { return up_; }
125
 
 
126
 
    int nregion();
127
 
    void get_region_names(const char *names[]);
128
 
    void get_wall_times(double *);
129
 
    void get_cpu_times(double *);
130
 
    void get_flops(double *);
131
 
    void get_depth(int *, int depth = 0);
132
 
};
133
 
 
134
97
//////////////////////////////////////////////////////////////////////
135
98
 
136
99
TimedRegion::TimedRegion(const char *name)
427
390
}
428
391
 
429
392
void
430
 
RegionTimer::exit(const char *name)
 
393
RegionTimer::exit(const char *name, bool do_not_throw)
431
394
{
432
395
  if (!current_ || (name && strcmp(name, current_->name()))) {
433
 
      ExEnv::errn() << "TimeRegion::exit(\"" << name << "\"):"
434
 
           << " current region"
435
 
           << " (\"" << current_->name() << "\")"
436
 
           << " doesn't match name"
437
 
           << endl;
438
 
      abort();
 
396
      if (do_not_throw) {
 
397
          // we have an error but cannot throw.  ignore this call
 
398
          return;
 
399
        }
 
400
      else {
 
401
          throw ProgrammingError("region mismatch",
 
402
                                 __FILE__, __LINE__, this->class_desc());
 
403
        }
439
404
    }
440
405
  if (cpu_time_) current_->cpu_exit(get_cpu_time());
441
406
  if (wall_time_) current_->wall_exit(get_wall_time());
442
407
  if (flops_) current_->flops_exit(get_flops());
443
408
  if (! current_->up()) {
444
 
      ExEnv::errn() << "RegionTimer::exit: already at top level" << endl;
445
 
      abort();
 
409
      if (do_not_throw) {
 
410
          // we have an error but cannot throw.  ignore this call
 
411
          return;
 
412
        }
 
413
      else {
 
414
          throw ProgrammingError("tried to exit top level",
 
415
                                 __FILE__, __LINE__, this->class_desc());
 
416
        }
446
417
    }
447
418
  current_ = current_->up();
448
419
}
726
697
Timer::~Timer()
727
698
{
728
699
  if (active_) {
729
 
      timer_->exit(name_.c_str());
 
700
      timer_->exit(name_.c_str(), true);
730
701
    }
731
702
}
732
703