1 | /* |
2 | * Copyright (c) 2012, 2019, 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_GC_SHARED_GCTRACETIME_HPP |
26 | #define SHARE_GC_SHARED_GCTRACETIME_HPP |
27 | |
28 | #include "logging/log.hpp" |
29 | #include "logging/logHandle.hpp" |
30 | #include "logging/logStream.hpp" |
31 | #include "memory/allocation.hpp" |
32 | #include "utilities/ticks.hpp" |
33 | |
34 | class GCTraceCPUTime : public StackObj { |
35 | bool _active; // true if times will be measured and printed |
36 | double _starting_user_time; // user time at start of measurement |
37 | double _starting_system_time; // system time at start of measurement |
38 | double _starting_real_time; // real time at start of measurement |
39 | public: |
40 | GCTraceCPUTime(); |
41 | ~GCTraceCPUTime(); |
42 | }; |
43 | |
44 | class GCTimer; |
45 | |
46 | class GCTraceTimeImpl : public StackObj { |
47 | private: |
48 | LogTargetHandle _out_start; |
49 | LogTargetHandle _out_stop; |
50 | bool _enabled; |
51 | Ticks _start_ticks; |
52 | const char* _title; |
53 | GCCause::Cause _gc_cause; |
54 | GCTimer* _timer; |
55 | size_t _heap_usage_before; |
56 | |
57 | void log_start(jlong start_counter); |
58 | void log_stop(jlong start_counter, jlong stop_counter); |
59 | void time_stamp(Ticks& ticks); |
60 | |
61 | public: |
62 | GCTraceTimeImpl(LogTargetHandle out_start, LogTargetHandle out_end, const char* title, GCTimer* timer = NULL, GCCause::Cause gc_cause = GCCause::_no_gc, bool log_heap_usage = false); |
63 | ~GCTraceTimeImpl(); |
64 | }; |
65 | |
66 | template <LogLevelType Level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag> |
67 | class GCTraceTimeImplWrapper : public StackObj { |
68 | GCTraceTimeImpl _impl; |
69 | public: |
70 | GCTraceTimeImplWrapper(const char* title, GCTimer* timer = NULL, GCCause::Cause gc_cause = GCCause::_no_gc, bool log_heap_usage = false); |
71 | ~GCTraceTimeImplWrapper(); |
72 | }; |
73 | |
74 | // Similar to GCTraceTimeImpl but is intended for concurrent phase logging, |
75 | // which is a bit simpler and should always print the start line, i.e. not add the "start" tag. |
76 | template <LogLevelType Level, LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG, |
77 | LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG> |
78 | class GCTraceConcTimeImpl : public StackObj { |
79 | private: |
80 | bool _enabled; |
81 | jlong _start_time; |
82 | const char* _title; |
83 | public: |
84 | GCTraceConcTimeImpl(const char* title); |
85 | ~GCTraceConcTimeImpl(); |
86 | jlong start_time() { return _start_time; } |
87 | }; |
88 | |
89 | #endif // SHARE_GC_SHARED_GCTRACETIME_HPP |
90 | |