timer.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.12 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 
00025 # include "incls/_precompiled.incl"
00026 # include "incls/_timer.cpp.incl"
00027 
00028 void timer::start() { 
00029   os::updateTimes();
00030   userTime   = os::userTime();
00031   systemTime = os::systemTime();
00032 }
00033 
00034 void timer::stop() {
00035   os::updateTimes();
00036   userTime   = os::userTime()   - userTime;
00037   systemTime = os::systemTime() - systemTime;
00038 }
00039 
00040 double timer::seconds() {
00041   return userTime;
00042 }
00043 
00044 void timer::print() {
00045   std->print_cr("%3.3f", userTime);
00046 }
00047 
00048 void elapsedTimer::start() {
00049   counter = os::elapsed_counter();
00050 }
00051 
00052 void elapsedTimer::stop() {
00053   counter = os::elapsed_counter() - counter;
00054 }
00055 
00056 double elapsedTimer::seconds() {
00057   double count = counter.as_double();
00058   double freq  = os::elapsed_frequency().as_double();
00059   return count/freq;
00060 }
00061 
00062 void elapsedTimer::print() {
00063   std->print_cr("%3.3f", seconds());
00064 }
00065 
00066 TimeStamp::TimeStamp() : counter(0,0) {
00067 }
00068 
00069 void TimeStamp::update() {
00070   counter = os::elapsed_counter();
00071 }
00072 
00073 double TimeStamp::seconds() {
00074   long_int new_count = os::elapsed_counter();
00075   double count = (new_count - counter).as_double();
00076   double freq  = os::elapsed_frequency().as_double();
00077   return count/freq;
00078 }
00079 
00080 TraceTime::TraceTime(char* title, bool doit) {
00081   active = doit;
00082   if (active) {
00083     std->print("[%s", title);
00084     t.start();
00085   }
00086 }
00087 
00088 TraceTime::~TraceTime() {
00089   if (active) {
00090     t.stop();
00091     std->print_cr(", %3.3f secs]", t.seconds());
00092   }
00093 }
00094 

Generated on Mon Oct 9 13:37:29 2006 for Strongtalk VM by  doxygen 1.4.7