Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
sampling_impl.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// sampling profiler implementation for Realm
19
20#ifndef REALM_SAMPLING_IMPL_H
21#define REALM_SAMPLING_IMPL_H
22
23#include "realm/sampling.h"
24#include "realm/threads.h"
25
26namespace Realm {
27
28 class SamplingProfilerImpl;
29
31 public:
32 GaugeSampleBuffer(int _sampler_id);
33 virtual ~GaugeSampleBuffer(void);
34
35 virtual void write_data(int fd) = 0;
36
41 };
42
43 template <typename T>
45 public:
46 GaugeSampleBufferImpl(int _sampler_id, size_t _reserve);
47
48 virtual void write_data(int fd);
49
50 std::vector<typename T::Sample> samples;
51 std::vector<unsigned short> run_lengths;
52 };
53
55 public:
56 GaugeSampler(int _sampler_id, SamplingProfilerImpl *_profiler);
57 virtual ~GaugeSampler(void);
58
59 virtual bool sample_gauge(int sample_index) = 0;
60 virtual GaugeSampleBuffer *buffer_swap(size_t new_buffer_size,
61 bool nonempty_only = false) = 0;
62
63 protected:
66
67 template <typename T>
70 template <typename T>
73 template <typename T>
76
79 Mutex mutex; // prevents deletion of a gauge during sampling
82 };
83
84 template <typename T>
86 public:
87 GaugeSamplerImpl(int _sampler_id, SamplingProfilerImpl *_profiler, T *_gauge,
89
90 virtual bool sample_gauge(int sample_index);
91 virtual GaugeSampleBuffer *buffer_swap(size_t new_buffer_size,
92 bool nonempty_only = false);
93
94 protected:
98 };
99
111
112 template <typename T>
120
122 protected:
123 friend class SamplingProfiler;
124
125 SamplingProfilerImpl(bool _is_default);
127
128 public:
129 void configure_from_cmdline(std::vector<std::string> &cmdline,
130 CoreReservationSet &crs);
131
132 void flush_data(void);
133 void shutdown(void);
134
136
137 template <typename T>
139
141
142 void sampler_loop(void);
143
144 protected:
145 bool parse_profile_pattern(const std::string &s);
146
153 std::vector<std::string> cfg_patterns;
156
157 bool pattern_match(const std::string &name) const;
158
159 // list of active samplers
160 std::vector<SampleFile::PacketNewGauge *> new_sampler_infos;
163
164 // we don't create samplers until we're configured - defer any additions that
165 // come before that
167
174 };
175
176}; // namespace Realm
177
178#endif
Definition threads.h:382
Definition threads.h:342
Definition sampling_impl.h:113
virtual GaugeSampler * create_sampler(int sampler_id, SamplingProfilerImpl *profiler, SampleFile::PacketNewGauge *info)
DelayedGaugeAdditionImpl(ProfilingGauges::Gauge *_gauge, DelayedGaugeAddition *_next)
Definition sampling_impl.h:100
DelayedGaugeAddition * next
Definition sampling_impl.h:109
virtual ~DelayedGaugeAddition(void)
DelayedGaugeAddition(ProfilingGauges::Gauge *_gauge, DelayedGaugeAddition *_next)
ProfilingGauges::Gauge * gauge
Definition sampling_impl.h:108
virtual GaugeSampler * create_sampler(int sampler_id, SamplingProfilerImpl *profiler, SampleFile::PacketNewGauge *info)=0
Definition sampling_impl.h:44
virtual void write_data(int fd)
GaugeSampleBufferImpl(int _sampler_id, size_t _reserve)
std::vector< typename T::Sample > samples
Definition sampling_impl.h:50
std::vector< unsigned short > run_lengths
Definition sampling_impl.h:51
Definition sampling_impl.h:30
int first_sample
Definition sampling_impl.h:39
virtual void write_data(int fd)=0
GaugeSampleBuffer(int _sampler_id)
int compressed_len
Definition sampling_impl.h:38
virtual ~GaugeSampleBuffer(void)
int sampler_id
Definition sampling_impl.h:37
int last_sample
Definition sampling_impl.h:40
Definition sampling_impl.h:85
T * gauge
Definition sampling_impl.h:95
virtual bool sample_gauge(int sample_index)
GaugeSampleBufferImpl< T > * buffer
Definition sampling_impl.h:97
GaugeSamplerImpl(int _sampler_id, SamplingProfilerImpl *_profiler, T *_gauge, SampleFile::PacketNewGauge *info)
virtual GaugeSampleBuffer * buffer_swap(size_t new_buffer_size, bool nonempty_only=false)
size_t buffer_size
Definition sampling_impl.h:96
Definition sampling_impl.h:54
virtual ~GaugeSampler(void)
bool gauge_exists
Definition sampling_impl.h:80
void perform_sample(ProfilingGauges::EventCounter< T > &gauge, typename ProfilingGauges::EventCounter< T >::Sample &sample)
SamplingProfilerImpl * profiler
Definition sampling_impl.h:78
virtual bool sample_gauge(int sample_index)=0
virtual GaugeSampleBuffer * buffer_swap(size_t new_buffer_size, bool nonempty_only=false)=0
void perform_sample(ProfilingGauges::AbsoluteRangeGauge< T > &gauge, typename ProfilingGauges::AbsoluteRangeGauge< T >::Sample &sample)
void perform_sample(ProfilingGauges::AbsoluteGauge< T > &gauge, typename ProfilingGauges::AbsoluteGauge< T >::Sample &sample)
int sampler_id
Definition sampling_impl.h:77
GaugeSampler * next
Definition sampling_impl.h:81
Mutex mutex
Definition sampling_impl.h:79
GaugeSampler(int _sampler_id, SamplingProfilerImpl *_profiler)
Definition sampling.h:148
Definition sampling.h:48
Definition sampling_impl.h:121
atomic< int > next_sampler_id
Definition sampling_impl.h:154
CoreReservation * core_rsrv
Definition sampling_impl.h:168
bool is_default
Definition sampling_impl.h:147
bool is_shut_down
Definition sampling_impl.h:149
Mutex mutex
Definition sampling_impl.h:148
bool pattern_match(const std::string &name) const
void configure_from_cmdline(std::vector< std::string > &cmdline, CoreReservationSet &crs)
Thread * sampling_thread
Definition sampling_impl.h:169
bool cfg_enabled
Definition sampling_impl.h:150
bool parse_profile_pattern(const std::string &s)
int output_fd
Definition sampling_impl.h:170
size_t cfg_buffer_size
Definition sampling_impl.h:152
std::vector< SampleFile::PacketNewGauge * > new_sampler_infos
Definition sampling_impl.h:160
void remove_gauge(ProfilingGauges::Gauge *gauge, GaugeSampler *sampler)
GaugeSampler * add_gauge(T *gauge)
ProfilingGauges::AbsoluteGauge< long long > * sampling_start
Definition sampling_impl.h:172
DelayedGaugeAddition * delayed_additions
Definition sampling_impl.h:166
ProfilingGauges::EventCounter< long long > * sampling_time
Definition sampling_impl.h:173
SamplingProfilerImpl(bool _is_default)
atomic< int > next_sample_index
Definition sampling_impl.h:155
bool flush_requested
Definition sampling_impl.h:171
std::vector< std::string > cfg_patterns
Definition sampling_impl.h:153
GaugeSampler ** sampler_tail
Definition sampling_impl.h:162
GaugeSampler * sampler_head
Definition sampling_impl.h:161
size_t cfg_sample_interval
Definition sampling_impl.h:151
static SamplingProfiler & get_profiler(void)
bool is_configured
Definition sampling_impl.h:149
Definition sampling.h:173
Definition threads.h:89
Definition mutex.h:223
Definition atomics.h:31
Definition activemsg.h:38
Definition sampling.h:211