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