-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathjfrCPUTimeThreadSampler.hpp
More file actions
169 lines (117 loc) · 4.67 KB
/
jfrCPUTimeThreadSampler.hpp
File metadata and controls
169 lines (117 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (c) 2025 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_JFR_PERIODIC_SAMPLING_JFRCPUTIMETHREADSAMPLER_HPP
#define SHARE_JFR_PERIODIC_SAMPLING_JFRCPUTIMETHREADSAMPLER_HPP
#include "jfr/utilities/jfrAllocation.hpp"
class JavaThread;
#if defined(LINUX)
#include "jfr/periodic/sampling/jfrSampleRequest.hpp"
#include "jfr/utilities/jfrTypes.hpp"
struct JfrCPUTimeSampleRequest {
JfrSampleRequest _request;
Tickspan _cpu_time_period;
JfrCPUTimeSampleRequest() {}
};
// Fixed size async-signal-safe SPSC linear queue backed by an array.
// Designed to be only used under lock and read linearly
class JfrCPUTimeTraceQueue {
// the default queue capacity, scaled if the sampling period is smaller than 10ms
// when the thread is started
static const u4 CPU_TIME_QUEUE_CAPACITY = 500;
JfrCPUTimeSampleRequest* _data;
volatile u4 _capacity;
// next unfilled index
volatile u4 _head;
volatile u4 _lost_samples;
volatile u4 _lost_samples_due_to_queue_full;
static const u4 CPU_TIME_QUEUE_INITIAL_CAPACITY = 20;
static const u4 CPU_TIME_QUEUE_MAX_CAPACITY = 2000;
public:
JfrCPUTimeTraceQueue(u4 capacity);
~JfrCPUTimeTraceQueue();
// signal safe, but can't be interleaved with dequeue
bool enqueue(JfrCPUTimeSampleRequest& trace);
JfrCPUTimeSampleRequest& at(u4 index);
u4 size() const;
void set_size(u4 size);
u4 capacity() const;
// deletes all samples in the queue
void set_capacity(u4 capacity);
bool is_empty() const;
u4 lost_samples() const;
void increment_lost_samples();
void increment_lost_samples_due_to_queue_full();
// returns the previous lost samples count
u4 get_and_reset_lost_samples();
u4 get_and_reset_lost_samples_due_to_queue_full();
void resize_if_needed();
// init the queue capacity
void init();
void clear();
};
class JfrCPUSamplerThread;
class JfrCPUSamplerThrottle;
class JfrCPUTimeThreadSampling : public JfrCHeapObj {
friend class JfrRecorder;
private:
JfrCPUSamplerThread* _sampler;
void create_sampler(JfrCPUSamplerThrottle& throttle);
void set_throttle_value(JfrCPUSamplerThrottle& throttle);
JfrCPUTimeThreadSampling();
~JfrCPUTimeThreadSampling();
static JfrCPUTimeThreadSampling& instance();
static JfrCPUTimeThreadSampling* create();
static void destroy();
void update_run_state(JfrCPUSamplerThrottle& throttle);
static void set_rate(JfrCPUSamplerThrottle& throttle);
public:
static void set_rate(double rate);
static void set_period(u8 nanos);
static void on_javathread_create(JavaThread* thread);
static void on_javathread_terminate(JavaThread* thread);
void handle_timer_signal(siginfo_t* info, void* context);
static void send_empty_event(const JfrTicks& start_time, traceid tid, Tickspan cpu_time_period);
static void send_event(const JfrTicks& start_time, traceid sid, traceid tid, Tickspan cpu_time_period, bool biased);
static void send_lost_event(const JfrTicks& time, traceid tid, s4 lost_samples);
static void trigger_async_processing_of_cpu_time_jfr_requests();
DEBUG_ONLY(static bool set_out_of_stack_walking_enabled(bool runnable);)
};
#else
// a basic implementation on other platforms that
// emits warnings
class JfrCPUTimeThreadSampling : public JfrCHeapObj {
friend class JfrRecorder;
private:
static JfrCPUTimeThreadSampling& instance();
static JfrCPUTimeThreadSampling* create();
static void destroy();
public:
static void set_rate(double rate);
static void set_period(u8 nanos);
static void on_javathread_create(JavaThread* thread);
static void on_javathread_terminate(JavaThread* thread);
DEBUG_ONLY(static bool set_out_of_stack_walking_enabled(bool runnable));
};
#endif // defined(LINUX)
#endif // SHARE_JFR_PERIODIC_SAMPLING_JFRCPUTIMETHREADSAMPLER_HPP