timer.hpp revision 4141
45N/A/*
553N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
45N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45N/A *
45N/A * This code is free software; you can redistribute it and/or modify it
45N/A * under the terms of the GNU General Public License version 2 only, as
45N/A * published by the Free Software Foundation.
45N/A *
45N/A * This code is distributed in the hope that it will be useful, but WITHOUT
45N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45N/A * version 2 for more details (a copy is included in the LICENSE file that
45N/A * accompanied this code).
45N/A *
45N/A * You should have received a copy of the GNU General Public License version
45N/A * 2 along with this work; if not, write to the Free Software Foundation,
45N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
45N/A *
45N/A */
45N/A
45N/A#ifndef SHARE_VM_RUNTIME_TIMER_HPP
45N/A#define SHARE_VM_RUNTIME_TIMER_HPP
45N/A
45N/A#include "utilities/globalDefinitions.hpp"
45N/A
45N/A// Timers for simple measurement.
45N/A
45N/Aclass elapsedTimer VALUE_OBJ_CLASS_SPEC {
45N/A friend class VMStructs;
45N/A private:
45N/A jlong _counter;
45N/A jlong _start_counter;
45N/A bool _active;
45N/A public:
45N/A elapsedTimer() { _active = false; reset(); }
45N/A void add(elapsedTimer t);
45N/A void start();
45N/A void stop();
45N/A void reset() { _counter = 0; }
45N/A double seconds() const;
45N/A jlong milliseconds() const;
45N/A jlong ticks() const { return _counter; }
45N/A jlong active_ticks() const;
45N/A bool is_active() const { return _active; }
45N/A};
45N/A
45N/A// TimeStamp is used for recording when an event took place.
45N/Aclass TimeStamp VALUE_OBJ_CLASS_SPEC {
45N/A private:
45N/A jlong _counter;
45N/A public:
45N/A TimeStamp() { _counter = 0; }
45N/A void clear() { _counter = 0; }
45N/A // has the timestamp been updated since being created or cleared?
45N/A bool is_updated() const { return _counter != 0; }
45N/A // update to current elapsed time
45N/A void update();
45N/A // update to given elapsed time
45N/A void update_to(jlong ticks);
45N/A // returns seconds since updated
45N/A // (must not be in a cleared state: must have been previously updated)
45N/A double seconds() const;
45N/A jlong milliseconds() const;
45N/A // ticks elapsed between VM start and last update
45N/A jlong ticks() const { return _counter; }
45N/A // ticks elapsed since last update
45N/A jlong ticks_since_update() const;
45N/A};
45N/A
45N/A// TraceTime is used for tracing the execution time of a block
45N/A// Usage:
45N/A// { TraceTime t("block time")
// some_code();
// }
//
class TraceTime: public StackObj {
private:
bool _active; // do timing
bool _verbose; // report every timing
elapsedTimer _t; // timer
elapsedTimer* _accum; // accumulator
public:
// Constructors
TraceTime(const char* title,
bool doit = true);
TraceTime(const char* title,
elapsedTimer* accumulator,
bool doit = true,
bool verbose = false);
~TraceTime();
// Accessors
void set_verbose(bool verbose) { _verbose = verbose; }
bool verbose() const { return _verbose; }
// Activation
void suspend() { if (_active) _t.stop(); }
void resume() { if (_active) _t.start(); }
};
class TraceCPUTime: public StackObj {
private:
bool _active; // true if times will be measured and printed
bool _print_cr; // if true print carriage return at end
double _starting_user_time; // user time at start of measurement
double _starting_system_time; // system time at start of measurement
double _starting_real_time; // real time at start of measurement
outputStream* _logfile; // output is printed to this stream
bool _error; // true if an error occurred, turns off output
public:
TraceCPUTime(bool doit = true,
bool print_cr = true,
outputStream *logfile = NULL);
~TraceCPUTime();
};
class TimeHelper {
public:
static double counter_to_seconds(jlong counter);
};
#endif // SHARE_VM_RUNTIME_TIMER_HPP