diff options
Diffstat (limited to 'src/libavoid/timer.cpp')
| -rw-r--r-- | src/libavoid/timer.cpp | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/libavoid/timer.cpp b/src/libavoid/timer.cpp index e4349bea9..f8600acbe 100644 --- a/src/libavoid/timer.cpp +++ b/src/libavoid/timer.cpp @@ -2,31 +2,34 @@ * vim: ts=4 sw=4 et tw=0 wm=0 * * libavoid - Fast, Incremental, Object-avoiding Line Router - * Copyright (C) 2004-2006 Michael Wybrow <mjwybrow@users.sourceforge.net> + * + * Copyright (C) 2004-2008 Monash University * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. + * See the file LICENSE.LGPL distributed with the library. + * + * Licensees holding a valid commercial license may use this file in + * accordance with the commercial license agreement provided with the + * library. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net> */ + #include <cstdio> #include <cstdlib> -#include <cassert> -using std::abort; #include <climits> #include "libavoid/timer.h" +#include "libavoid/debug.h" +#include "libavoid/assertions.h" namespace Avoid { @@ -52,9 +55,9 @@ void Timer::Reset(void) } -void Timer::Register(const int t, const bool start) +void Timer::Register(const TimerIndex t, const bool start) { - assert(t != tmNon); + COLA_ASSERT(t != tmNon); if (type == tmNon) { @@ -73,11 +76,7 @@ void Timer::Register(const int t, const bool start) void Timer::Start(void) { - if (running) - { - fprintf(stderr, "ERROR: Timer already running in Timer::Start()\n"); - abort(); - } + COLA_ASSERT(!running); cStart[type] = clock(); // CPU time running = true; } @@ -85,11 +84,7 @@ void Timer::Start(void) void Timer::Stop(void) { - if (!running) - { - fprintf(stderr, "ERROR: Timer not running in Timer::Stop()\n"); - abort(); - } + COLA_ASSERT(running); clock_t cStop = clock(); // CPU time running = false; @@ -106,11 +101,7 @@ void Timer::Stop(void) cDiff = cStop - cStart[type]; } - if (cDiff > LONG_MAX) - { - fprintf(stderr, "Error: cDiff overflow in Timer:Stop()\n"); - abort(); - } + COLA_ASSERT(cDiff < LONG_MAX); if (type == tmPth) { @@ -136,11 +127,11 @@ void Timer::Stop(void) } -void Timer::PrintAll(void) +void Timer::PrintAll(FILE *fp) { - for (int i = 0; i < tmCount; i++) + for (unsigned int i = 0; i < tmCount; i++) { - Print(i); + Print((TimerIndex) i, fp); } } @@ -148,14 +139,14 @@ void Timer::PrintAll(void) #define toMsec(tot) ((bigclock_t) ((tot) / (((double) CLOCKS_PER_SEC) / 1000))) #define toAvg(tot, cnt) ((((cnt) > 0) ? ((long double) (tot)) / (cnt) : 0)) -void Timer::Print(const int t) +void Timer::Print(const TimerIndex t, FILE *fp) { bigclock_t avg = toMsec(toAvg(cTotal[t], cTally[t])); bigclock_t pind = toMsec(toAvg(cPath[t], cPathTally[t])); bigclock_t pavg = toMsec(toAvg(cPath[t], cTally[t])); double max = toMsec(cMax[t]); double pmax = toMsec(cPathMax[t]); - printf("\t%lld %d %lld %.0f %lld %d %lld %.0f %lld\n", + fprintf(fp, "\t%lld %d %lld %.0f %lld %d %lld %.0f %lld\n", cTotal[t], cTally[t], avg, max, cPath[t], cPathTally[t], pavg, pmax, pind); } |
