annotate src/share/vm/gc/shared/gcTraceTime.cpp @ 9396:983c56341c80

8134953: Make the GC ID available in a central place Reviewed-by: pliden, jmasa
author brutisso
date Wed, 30 Sep 2015 09:07:21 +0200
parents a4ae74ca2403
children f944761a3ce3
rev   line source
sla@4802 1 /*
pliden@8621 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
sla@4802 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sla@4802 4 *
sla@4802 5 * This code is free software; you can redistribute it and/or modify it
sla@4802 6 * under the terms of the GNU General Public License version 2 only, as
sla@4802 7 * published by the Free Software Foundation.
sla@4802 8 *
sla@4802 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sla@4802 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sla@4802 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sla@4802 12 * version 2 for more details (a copy is included in the LICENSE file that
sla@4802 13 * accompanied this code).
sla@4802 14 *
sla@4802 15 * You should have received a copy of the GNU General Public License version
sla@4802 16 * 2 along with this work; if not, write to the Free Software Foundation,
sla@4802 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sla@4802 18 *
sla@4802 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sla@4802 20 * or visit www.oracle.com if you need additional information or have any
sla@4802 21 * questions.
sla@4802 22 *
sla@4802 23 */
sla@4802 24
sla@4802 25 #include "precompiled.hpp"
pliden@8621 26 #include "gc/shared/gcTimer.hpp"
pliden@8621 27 #include "gc/shared/gcTrace.hpp"
pliden@8621 28 #include "gc/shared/gcTraceTime.hpp"
sla@4802 29 #include "runtime/globals.hpp"
sla@4802 30 #include "runtime/os.hpp"
sla@4802 31 #include "runtime/safepoint.hpp"
sla@4802 32 #include "runtime/thread.inline.hpp"
sla@4802 33 #include "runtime/timer.hpp"
sla@4802 34 #include "utilities/ostream.hpp"
mgronlun@5702 35 #include "utilities/ticks.inline.hpp"
sla@4802 36
sla@4802 37
brutisso@9396 38 GCTraceTimeImpl::GCTraceTimeImpl(const char* title, bool doit, bool print_cr, GCTimer* timer) :
mgronlun@5702 39 _title(title), _doit(doit), _print_cr(print_cr), _timer(timer), _start_counter() {
sla@4802 40 if (_doit || _timer != NULL) {
mgronlun@5702 41 _start_counter.stamp();
sla@4802 42 }
sla@4802 43
sla@4802 44 if (_timer != NULL) {
sla@4802 45 assert(SafepointSynchronize::is_at_safepoint(), "Tracing currently only supported at safepoints");
sla@4802 46 assert(Thread::current()->is_VM_thread(), "Tracing currently only supported from the VM thread");
sla@4802 47
sla@4802 48 _timer->register_gc_phase_start(title, _start_counter);
sla@4802 49 }
sla@4802 50
sla@4802 51 if (_doit) {
brutisso@9396 52 gclog_or_tty->gclog_stamp();
sla@4802 53 gclog_or_tty->print("[%s", title);
sla@4802 54 gclog_or_tty->flush();
sla@4802 55 }
sla@4802 56 }
sla@4802 57
brutisso@9392 58 GCTraceTimeImpl::~GCTraceTimeImpl() {
mgronlun@5702 59 Ticks stop_counter;
sla@4802 60
sla@4802 61 if (_doit || _timer != NULL) {
mgronlun@5702 62 stop_counter.stamp();
sla@4802 63 }
sla@4802 64
sla@4802 65 if (_timer != NULL) {
sla@4802 66 _timer->register_gc_phase_end(stop_counter);
sla@4802 67 }
sla@4802 68
sla@4802 69 if (_doit) {
mgronlun@5702 70 const Tickspan duration = stop_counter - _start_counter;
mgronlun@5702 71 double duration_in_seconds = TicksToTimeHelper::seconds(duration);
sla@4802 72 if (_print_cr) {
mgronlun@5702 73 gclog_or_tty->print_cr(", %3.7f secs]", duration_in_seconds);
sla@4802 74 } else {
mgronlun@5702 75 gclog_or_tty->print(", %3.7f secs]", duration_in_seconds);
sla@4802 76 }
sla@4802 77 gclog_or_tty->flush();
sla@4802 78 }
sla@4802 79 }