4141N/A/*
4141N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4141N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4141N/A *
4141N/A * This code is free software; you can redistribute it and/or modify it
4141N/A * under the terms of the GNU General Public License version 2 only, as
4141N/A * published by the Free Software Foundation.
4141N/A *
4141N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4141N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4141N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4141N/A * version 2 for more details (a copy is included in the LICENSE file that
4141N/A * accompanied this code).
4141N/A *
4141N/A * You should have received a copy of the GNU General Public License version
4141N/A * 2 along with this work; if not, write to the Free Software Foundation,
4141N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4141N/A *
4141N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4141N/A * or visit www.oracle.com if you need additional information or have any
4141N/A * questions.
4141N/A *
4141N/A */
4141N/A
4141N/A#include "precompiled.hpp"
4141N/A#include "gc_implementation/shared/gcTimer.hpp"
4141N/A#include "gc_implementation/shared/gcTraceTime.hpp"
4141N/A#include "runtime/globals.hpp"
4141N/A#include "runtime/os.hpp"
4141N/A#include "runtime/safepoint.hpp"
4141N/A#include "runtime/timer.hpp"
4141N/A#include "utilities/ostream.hpp"
4141N/A#ifdef TARGET_OS_FAMILY_linux
4141N/A# include "thread_linux.inline.hpp"
4141N/A#endif
4141N/A#ifdef TARGET_OS_FAMILY_solaris
4141N/A# include "thread_solaris.inline.hpp"
4141N/A#endif
4141N/A#ifdef TARGET_OS_FAMILY_windows
4141N/A# include "thread_windows.inline.hpp"
4141N/A#endif
4141N/A#ifdef TARGET_OS_FAMILY_bsd
4141N/A# include "thread_bsd.inline.hpp"
4141N/A#endif
4141N/A
4141N/A
4141N/AGCTraceTime::GCTraceTime(const char* title, bool doit, bool print_cr, GCTimer* timer) :
4141N/A _title(title), _doit(doit), _print_cr(print_cr), _timer(timer) {
4141N/A if (_doit || _timer != NULL) {
4141N/A _start_counter = os::elapsed_counter();
4141N/A }
4141N/A
4141N/A if (_timer != NULL) {
4141N/A assert(SafepointSynchronize::is_at_safepoint(), "Tracing currently only supported at safepoints");
4141N/A assert(Thread::current()->is_VM_thread(), "Tracing currently only supported from the VM thread");
4141N/A
4141N/A _timer->register_gc_phase_start(title, _start_counter);
4141N/A }
4141N/A
4141N/A if (_doit) {
4515N/A gclog_or_tty->date_stamp(PrintGCDateStamps);
4515N/A gclog_or_tty->stamp(PrintGCTimeStamps);
4141N/A gclog_or_tty->print("[%s", title);
4141N/A gclog_or_tty->flush();
4141N/A }
4141N/A}
4141N/A
4141N/AGCTraceTime::~GCTraceTime() {
4141N/A jlong stop_counter = 0;
4141N/A
4141N/A if (_doit || _timer != NULL) {
4141N/A stop_counter = os::elapsed_counter();
4141N/A }
4141N/A
4141N/A if (_timer != NULL) {
4141N/A _timer->register_gc_phase_end(stop_counter);
4141N/A }
4141N/A
4141N/A if (_doit) {
4141N/A double seconds = TimeHelper::counter_to_seconds(stop_counter - _start_counter);
4141N/A if (_print_cr) {
4141N/A gclog_or_tty->print_cr(", %3.7f secs]", seconds);
4141N/A } else {
4141N/A gclog_or_tty->print(", %3.7f secs]", seconds);
4141N/A }
4141N/A gclog_or_tty->flush();
4141N/A }
4141N/A}