1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
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
28 #include "trace/traceTime.hpp"
29 #include "utilities/macros.hpp"
30
31 enum EventStartTime {
32 UNTIMED,
33 TIMED
34 };
35
36 #if INCLUDE_TRACE
37 #include "trace/traceBackend.hpp"
38 #include "tracefiles/traceEventIds.hpp"
39 #include "utilities/ticks.hpp"
40
41 template<typename T>
42 class TraceEvent {
43 private:
44 bool _started;
45
46 protected:
47 jlong _startTime;
48 jlong _endTime;
49 DEBUG_ONLY(bool _committed;)
50
51 void set_starttime(const TracingTime& time) {
52 _startTime = time;
53 }
54
55 void set_endtime(const TracingTime& time) {
56 _endTime = time;
57 }
58
59 TraceEvent(EventStartTime timing=TIMED) :
60 _startTime(0),
61 _endTime(0),
62 _started(false)
63 #ifdef ASSERT
64 , _committed(false)
65 #endif
66 {
67 if (T::is_enabled()) {
68 _started = true;
69 if (TIMED == timing && !T::isInstant) {
70 static_cast<T*>(this)->set_starttime(Tracing::time());
71 }
72 }
73 }
74
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
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()) {
94 return;
|
1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
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
28 #include "jfr/utilities/jfrTraceTime.hpp"
29 #include "utilities/macros.hpp"
30
31 enum EventStartTime {
32 UNTIMED,
33 TIMED
34 };
35
36 #if INCLUDE_TRACE
37 #include "trace/traceBackend.hpp"
38 #include "tracefiles/traceEventIds.hpp"
39 #include "utilities/ticks.hpp"
40
41 template<typename T>
42 class TraceEvent {
43 private:
44 bool _started;
45
46 protected:
47 jlong _startTime;
48 jlong _endTime;
49 DEBUG_ONLY(bool _committed;)
50 void set_starttime(const JfrTraceTime& time) {
51 _startTime = time;
52 }
53
54 void set_endtime(const JfrTraceTime& time) {
55 _endTime = time;
56 }
57
58 TraceEvent(EventStartTime timing=TIMED) :
59 _startTime(0),
60 _endTime(0),
61 _started(false)
62 #ifdef ASSERT
63 , _committed(false)
64 #endif
65 {
66 if (T::is_enabled()) {
67 _started = true;
68 if (TIMED == timing && !T::isInstant) {
69 static_cast<T*>(this)->set_starttime(Tracing::time());
70 }
71 }
72 }
73 public:
74 void set_starttime(const Ticks& time) {
75 _startTime = time.value();
76 }
77
78 void set_endtime(const Ticks& time) {
79 _endTime = time.value();
80 }
81
82 static bool is_enabled() {
83 return Tracing::is_event_enabled(T::eventId);
84 }
85
86 bool should_commit() {
87 return _started;
88 }
89
90 void commit() {
91 if (!should_commit()) {
92 return;
|