47 out.print(" (%s)", GCCause::to_string(_gc_cause));
48 }
49 out.print_cr(" (%.3fs)", TimeHelper::counter_to_seconds(start_counter));
50 }
51 }
52
53 inline void GCTraceTimeImpl::log_stop(jlong start_counter, jlong stop_counter) {
54 double duration_in_ms = TimeHelper::counter_to_millis(stop_counter - start_counter);
55 double start_time_in_secs = TimeHelper::counter_to_seconds(start_counter);
56 double stop_time_in_secs = TimeHelper::counter_to_seconds(stop_counter);
57
58 LogStream out(_out_stop);
59
60 out.print("%s", _title);
61
62 if (_gc_cause != GCCause::_no_gc) {
63 out.print(" (%s)", GCCause::to_string(_gc_cause));
64 }
65
66 if (_heap_usage_before != SIZE_MAX) {
67 CollectedHeap* heap = Universe::heap();
68 size_t used_before_m = _heap_usage_before / M;
69 size_t used_m = heap->used() / M;
70 size_t capacity_m = heap->capacity() / M;
71 out.print(" " LOG_STOP_HEAP_FORMAT, used_before_m, used_m, capacity_m);
72 }
73
74 out.print_cr(" " LOG_STOP_TIME_FORMAT, start_time_in_secs, stop_time_in_secs, duration_in_ms);
75 }
76
77 inline void GCTraceTimeImpl::time_stamp(Ticks& ticks) {
78 if (_enabled || _timer != NULL) {
79 ticks.stamp();
80 }
81 }
82
83 inline GCTraceTimeImpl::GCTraceTimeImpl(LogTargetHandle out_start, LogTargetHandle out_stop, const char* title, GCTimer* timer, GCCause::Cause gc_cause, bool log_heap_usage) :
84 _enabled(out_stop.is_enabled()),
85 _out_start(out_start),
86 _out_stop(out_stop),
87 _start_ticks(),
88 _heap_usage_before(SIZE_MAX),
89 _title(title),
90 _gc_cause(gc_cause),
91 _timer(timer) {
92
93 time_stamp(_start_ticks);
94 if (_enabled) {
95 if (log_heap_usage) {
96 _heap_usage_before = Universe::heap()->used();
97 }
98 log_start(_start_ticks.value());
99 }
100 if (_timer != NULL) {
101 _timer->register_gc_phase_start(_title, _start_ticks);
102 }
103 }
104
105 inline GCTraceTimeImpl::~GCTraceTimeImpl() {
106 Ticks stop_ticks;
107 time_stamp(stop_ticks);
108 if (_enabled) {
109 log_stop(_start_ticks.value(), stop_ticks.value());
110 }
111 if (_timer != NULL) {
112 _timer->register_gc_phase_end(stop_ticks);
113 }
114 }
115
116 template <LogLevelType Level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag >
|
47 out.print(" (%s)", GCCause::to_string(_gc_cause));
48 }
49 out.print_cr(" (%.3fs)", TimeHelper::counter_to_seconds(start_counter));
50 }
51 }
52
53 inline void GCTraceTimeImpl::log_stop(jlong start_counter, jlong stop_counter) {
54 double duration_in_ms = TimeHelper::counter_to_millis(stop_counter - start_counter);
55 double start_time_in_secs = TimeHelper::counter_to_seconds(start_counter);
56 double stop_time_in_secs = TimeHelper::counter_to_seconds(stop_counter);
57
58 LogStream out(_out_stop);
59
60 out.print("%s", _title);
61
62 if (_gc_cause != GCCause::_no_gc) {
63 out.print(" (%s)", GCCause::to_string(_gc_cause));
64 }
65
66 if (_heap_usage_before != SIZE_MAX) {
67 CollectedHeap* heap = GC::gc()->heap();
68 size_t used_before_m = _heap_usage_before / M;
69 size_t used_m = heap->used() / M;
70 size_t capacity_m = heap->capacity() / M;
71 out.print(" " LOG_STOP_HEAP_FORMAT, used_before_m, used_m, capacity_m);
72 }
73
74 out.print_cr(" " LOG_STOP_TIME_FORMAT, start_time_in_secs, stop_time_in_secs, duration_in_ms);
75 }
76
77 inline void GCTraceTimeImpl::time_stamp(Ticks& ticks) {
78 if (_enabled || _timer != NULL) {
79 ticks.stamp();
80 }
81 }
82
83 inline GCTraceTimeImpl::GCTraceTimeImpl(LogTargetHandle out_start, LogTargetHandle out_stop, const char* title, GCTimer* timer, GCCause::Cause gc_cause, bool log_heap_usage) :
84 _enabled(out_stop.is_enabled()),
85 _out_start(out_start),
86 _out_stop(out_stop),
87 _start_ticks(),
88 _heap_usage_before(SIZE_MAX),
89 _title(title),
90 _gc_cause(gc_cause),
91 _timer(timer) {
92
93 time_stamp(_start_ticks);
94 if (_enabled) {
95 if (log_heap_usage) {
96 _heap_usage_before = GC::gc()->heap()->used();
97 }
98 log_start(_start_ticks.value());
99 }
100 if (_timer != NULL) {
101 _timer->register_gc_phase_start(_title, _start_ticks);
102 }
103 }
104
105 inline GCTraceTimeImpl::~GCTraceTimeImpl() {
106 Ticks stop_ticks;
107 time_stamp(stop_ticks);
108 if (_enabled) {
109 log_stop(_start_ticks.value(), stop_ticks.value());
110 }
111 if (_timer != NULL) {
112 _timer->register_gc_phase_end(stop_ticks);
113 }
114 }
115
116 template <LogLevelType Level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag >
|