Skip to content

Commit afc260f

Browse files
committed
fix: memory profile feature compilation failed
1 parent bf6553d commit afc260f

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

agent/src/ebpf_dispatcher.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl EbpfCollector {
534534
let Some(m_ctx) = (ctx as *mut memory_profile::MemoryContext).as_mut() else {
535535
return;
536536
};
537-
m_ctx.update(data, PROFILE_STACK_COMPRESSION);
537+
m_ctx.update(data);
538538
m_ctx.report(
539539
Duration::from_nanos(ts_nanos),
540540
EBPF_PROFILE_SENDER.as_mut().unwrap(),
@@ -568,20 +568,24 @@ impl EbpfCollector {
568568
profile.cpu = data.cpu;
569569
profile.count = data.count as u32;
570570
profile.wide_count = data.count;
571-
profile.data =
572-
slice::from_raw_parts(data.stack_data as *mut u8, data.stack_data_len as usize)
573-
.to_vec();
574-
let container_id =
575-
CStr::from_ptr(data.container_id.as_ptr() as *const libc::c_char).to_string_lossy();
571+
let profile_data =
572+
slice::from_raw_parts(data.stack_data as *mut u8, data.stack_data_len as usize);
576573
if PROFILE_STACK_COMPRESSION {
577-
match compress(&profile.data, 0) {
574+
match compress(&profile_data, 0) {
578575
Ok(compressed_data) => {
579576
profile.data_compressed = true;
580577
profile.data = compressed_data;
581578
}
582-
Err(e) => debug!("failed to compress ebpf profile: {:?}", e),
579+
Err(e) => {
580+
profile.data = profile_data.to_vec();
581+
debug!("failed to compress ebpf profile: {:?}", e);
582+
}
583583
}
584+
} else {
585+
profile.data = profile_data.to_vec();
584586
}
587+
let container_id =
588+
CStr::from_ptr(data.container_id.as_ptr() as *const libc::c_char).to_string_lossy();
585589
if let Some(policy_getter) = POLICY_GETTER.as_ref() {
586590
profile.pod_id = policy_getter.lookup_pod_id(&container_id);
587591
}
@@ -824,7 +828,10 @@ impl EbpfCollector {
824828
let mut contexts: [*mut c_void; 3] = [ptr::null_mut(); 3];
825829
#[cfg(feature = "extended_profile")]
826830
{
827-
let mp_ctx = memory_profile::MemoryContext::new(memory.report_interval);
831+
let mp_ctx = memory_profile::MemoryContext::new(
832+
memory.report_interval,
833+
ebpf_conf.preprocess.stack_compression,
834+
);
828835
handle.memory_profile_settings = Some(mp_ctx.settings());
829836
contexts[ebpf::PROFILER_CTX_MEMORY_IDX] =
830837
Box::into_raw(Box::new(mp_ctx)) as *mut c_void;

agent/src/ebpf_dispatcher/memory_profile.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,21 @@ impl ProcessAllocInfo {
7676
profile.u_stack_id = data.u_stack_id;
7777
profile.cpu = data.cpu;
7878
profile.wide_count = 0;
79-
profile.data =
80-
slice::from_raw_parts(data.stack_data as *mut u8, data.stack_data_len as usize)
81-
.to_vec();
79+
let profile_data =
80+
slice::from_raw_parts(data.stack_data as *mut u8, data.stack_data_len as usize);
8281
if stack_compression {
83-
match compress(&profile.data, 0) {
82+
match compress(&profile_data, 0) {
8483
Ok(compressed_data) => {
8584
profile.data_compressed = true;
8685
profile.data = compressed_data;
8786
}
88-
Err(e) => debug!("failed to compress ebpf memory profile: {:?}", e),
87+
Err(e) => {
88+
profile_data.to_vec();
89+
debug!("failed to compress ebpf memory profile: {:?}", e);
90+
}
8991
}
92+
} else {
93+
profile.data = profile_data.to_vec();
9094
}
9195

9296
let container_id =
@@ -184,18 +188,20 @@ pub struct MemoryContext {
184188

185189
report_interval_secs: Arc<AtomicU8>,
186190
last_report: Duration,
191+
stack_compression: bool,
187192
}
188193

189194
impl MemoryContext {
190195
// There's a small difference (less than 1s) between start time from profiler and from procfs rust lib.
191196
// If cached stime from profiler plus THRESHOLD is smaller than start time from procfs, it's a process restart
192197
const PROCESS_RESTART_THRESHOLD: Duration = Duration::from_secs(3);
193198

194-
pub fn new(report_interval: Duration) -> Self {
199+
pub fn new(report_interval: Duration, stack_compression: bool) -> Self {
195200
Self {
196201
processes: Default::default(),
197202
report_interval_secs: Arc::new(AtomicU8::new(report_interval.as_secs() as u8)),
198203
last_report: Default::default(),
204+
stack_compression: stack_compression,
199205
}
200206
}
201207

@@ -210,7 +216,7 @@ impl MemoryContext {
210216
self.processes
211217
.entry(data.pid)
212218
.or_insert(Default::default())
213-
.update(data);
219+
.update(data, self.stack_compression);
214220
}
215221

216222
pub fn report(&mut self, timestamp: Duration, sender: &mut DebugSender<Profile>) {

0 commit comments

Comments
 (0)