author | redestad |
Mon, 28 Aug 2017 00:20:35 +0200 | |
changeset 46994 | 7663ce98384b |
parent 36385 | 09b091ad5de2 |
permissions | -rw-r--r-- |
18025 | 1 |
/* |
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
18025 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_TRACE_TRACEEVENT_HPP |
|
26 |
#define SHARE_VM_TRACE_TRACEEVENT_HPP |
|
27 |
||
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
28 |
#include "trace/traceTime.hpp" |
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
29 |
#include "utilities/macros.hpp" |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
30 |
|
18025 | 31 |
enum EventStartTime { |
32 |
UNTIMED, |
|
33 |
TIMED |
|
34 |
}; |
|
35 |
||
36 |
#if INCLUDE_TRACE |
|
37 |
#include "trace/traceBackend.hpp" |
|
38 |
#include "tracefiles/traceEventIds.hpp" |
|
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
39 |
#include "utilities/ticks.hpp" |
18025 | 40 |
|
41 |
template<typename T> |
|
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
42 |
class TraceEvent { |
18025 | 43 |
private: |
44 |
bool _started; |
|
45 |
||
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
46 |
protected: |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
47 |
jlong _startTime; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
48 |
jlong _endTime; |
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
49 |
DEBUG_ONLY(bool _committed;) |
21767
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
50 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
51 |
void set_starttime(const TracingTime& time) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
52 |
_startTime = time; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
53 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
54 |
|
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
55 |
void set_endtime(const TracingTime& time) { |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
56 |
_endTime = time; |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
57 |
} |
41eaa9a17059
8028128: Add a type safe alternative for working with counter based data
mgronlun
parents:
18025
diff
changeset
|
58 |
|
18025 | 59 |
TraceEvent(EventStartTime timing=TIMED) : |
60 |
_startTime(0), |
|
61 |
_endTime(0), |
|
62 |
_started(false) |
|
63 |
#ifdef ASSERT |
|
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
64 |
, _committed(false) |
18025 | 65 |
#endif |
66 |
{ |
|
67 |
if (T::is_enabled()) { |
|
68 |
_started = true; |
|
36385 | 69 |
if (TIMED == timing && !T::isInstant) { |
70 |
static_cast<T*>(this)->set_starttime(Tracing::time()); |
|
18025 | 71 |
} |
72 |
} |
|
73 |
} |
|
74 |
||
36385 | 75 |
public: |
76 |
void set_starttime(const Ticks& time) { |
|
77 |
_startTime = time.value(); |
|
78 |
} |
|
79 |
||
80 |
void set_endtime(const Ticks& time) { |
|
81 |
_endTime = time.value(); |
|
82 |
} |
|
83 |
||
18025 | 84 |
static bool is_enabled() { |
85 |
return Tracing::is_event_enabled(T::eventId); |
|
86 |
} |
|
87 |
||
88 |
bool should_commit() { |
|
89 |
return _started; |
|
90 |
} |
|
91 |
||
92 |
void commit() { |
|
93 |
if (!should_commit()) { |
|
36385 | 94 |
return; |
18025 | 95 |
} |
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
96 |
assert(!_committed, "event already committed"); |
36384 | 97 |
if (_startTime == 0) { |
98 |
static_cast<T*>(this)->set_starttime(Tracing::time()); |
|
36385 | 99 |
} else if (_endTime == 0) { |
100 |
static_cast<T*>(this)->set_endtime(Tracing::time()); |
|
18025 | 101 |
} |
102 |
if (static_cast<T*>(this)->should_write()) { |
|
103 |
static_cast<T*>(this)->writeEvent(); |
|
46994
7663ce98384b
8179040: Avoid Ticks::now calls when EventClassLoad is not enabled
redestad
parents:
36385
diff
changeset
|
104 |
DEBUG_ONLY(_committed = true;) |
18025 | 105 |
} |
106 |
} |
|
107 |
||
36385 | 108 |
static TraceEventId id() { |
18025 | 109 |
return T::eventId; |
110 |
} |
|
111 |
||
36385 | 112 |
static bool is_instant() { |
18025 | 113 |
return T::isInstant; |
114 |
} |
|
115 |
||
36385 | 116 |
static bool is_requestable() { |
18025 | 117 |
return T::isRequestable; |
118 |
} |
|
119 |
||
36385 | 120 |
static bool has_thread() { |
18025 | 121 |
return T::hasThread; |
122 |
} |
|
123 |
||
36385 | 124 |
static bool has_stacktrace() { |
18025 | 125 |
return T::hasStackTrace; |
126 |
} |
|
127 |
}; |
|
128 |
||
27673
df559a888b9f
8065361: Fixup headers and definitions for INCLUDE_TRACE
mgronlun
parents:
21767
diff
changeset
|
129 |
#endif // INCLUDE_TRACE |
df559a888b9f
8065361: Fixup headers and definitions for INCLUDE_TRACE
mgronlun
parents:
21767
diff
changeset
|
130 |
#endif // SHARE_VM_TRACE_TRACEEVENT_HPP |