hotspot/src/share/vm/runtime/timerTrace.hpp
author kvn
Mon, 10 Jul 2017 14:28:40 -0700
changeset 45806 36707109c109
parent 37242 91e5f98fff6f
permissions -rw-r--r--
8184036: Restore -XX:UseAVX=3 as product value Reviewed-by: dlong, roland
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
#ifndef SHARE_VM_RUNTIME_TIMERTRACE_HPP
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    26
#define SHARE_VM_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
#include "logging/log.hpp"
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    29
#include "utilities/globalDefinitions.hpp"
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    30
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    31
// TraceTime is used for tracing the execution time of a block
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    32
// Usage:
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    33
//  {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    34
//    TraceTime t("some timer", TIMERTRACE_LOG(Info, startuptime, tagX...));
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    35
//    some_code();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    36
//  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    37
//
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
typedef void (*TraceTimerLogPrintFunc)(const char*, ...);
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    40
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37161
diff changeset
    41
// We need to explicit take address of LogImpl<>write<> and static cast
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    42
// due to MSVC is not compliant with templates two-phase lookup
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    43
#define TRACETIME_LOG(TT_LEVEL, ...) \
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37161
diff changeset
    44
    log_is_enabled(TT_LEVEL, __VA_ARGS__) ? static_cast<TraceTimerLogPrintFunc>(&LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::TT_LEVEL>) : (TraceTimerLogPrintFunc)NULL
37161
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    45
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    46
class TraceTime: public StackObj {
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    47
 private:
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    48
  bool          _active;    // do timing
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    49
  bool          _verbose;   // report every timing
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    50
  elapsedTimer  _t;         // timer
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    51
  elapsedTimer* _accum;     // accumulator
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    52
  const char*   _title;     // name of timer
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    53
  TraceTimerLogPrintFunc _print;
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
 public:
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    56
  // Constructors
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    57
  TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    58
            bool doit = true);
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    59
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    60
  TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    61
            elapsedTimer* accumulator,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    62
            bool doit = true,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    63
            bool verbose = false);
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    64
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    65
  TraceTime(const char* title,
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    66
            TraceTimerLogPrintFunc ttlpf);
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
  ~TraceTime();
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    69
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    70
  // Accessors
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    71
  void set_verbose(bool verbose)  { _verbose = verbose; }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    72
  bool verbose() const            { return _verbose;    }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    73
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    74
  // Activation
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    75
  void suspend()  { if (_active) _t.stop();  }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    76
  void resume()   { if (_active) _t.start(); }
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    77
};
e881f320966e 8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
diff changeset
    78
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
#endif // SHARE_VM_RUNTIME_TIMERTRACE_HPP