hotspot/src/share/vm/runtime/timerTrace.cpp
author rehn
Tue, 15 Mar 2016 14:41:07 +0100
changeset 37161 e881f320966e
permissions -rw-r--r--
8150015: Integrate TraceTime with Unified Logging more seamlessly Reviewed-by: coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     1
/*
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     4
 *
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     8
 *
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    13
 * accompanied this code).
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    14
 *
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    18
 *
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    21
 * questions.
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    22
 *
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    23
 */
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    24
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    25
#include "precompiled.hpp"
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    26
#include "runtime/timerTrace.hpp"
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    27
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    28
TraceTime::TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    29
                     bool doit) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    30
  _active   = doit;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    31
  _verbose  = true;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    32
  _title    = title;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    33
  _print    = NULL;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    34
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    35
  if (_active) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    36
    _accum = NULL;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    37
    _t.start();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    38
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    39
}
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    40
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    41
TraceTime::TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    42
                     elapsedTimer* accumulator,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    43
                     bool doit,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    44
                     bool verbose) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    45
  _active   = doit;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    46
  _verbose  = verbose;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    47
  _title    = title;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    48
  _print    = NULL;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    49
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    50
  if (_active) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    51
    _accum = accumulator;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    52
    _t.start();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    53
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    54
}
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    55
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    56
TraceTime::TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    57
                     TraceTimerLogPrintFunc ttlpf) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    58
  _active   = ttlpf!= NULL;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    59
  _verbose  = true;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    60
  _title    = title;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    61
  _print    = ttlpf;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    62
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    63
  if (_active) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    64
    _accum = NULL;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    65
    _t.start();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    66
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    67
}
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    68
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    69
TraceTime::~TraceTime() {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    70
  if (!_active) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    71
    return;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    72
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    73
  _t.stop();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    74
  if (_accum != NULL) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    75
    _accum->add(_t);
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    76
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    77
  if (!_verbose) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    78
    return;
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    79
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    80
  if (_print) {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    81
    _print("%s, %3.7f secs", _title, _t.seconds());
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    82
  } else {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    83
    tty->print_cr("[%s, %3.7f secs]", _title, _t.seconds());
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    84
    tty->flush();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    85
  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    86
}
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    87