Skip to content

Commit b771d52

Browse files
authored
update the prost generated file and remove malloc_free (#188)
* update prost file Signed-off-by: YangKeao <[email protected]> * remove malloc free test Signed-off-by: YangKeao <[email protected]> Signed-off-by: YangKeao <[email protected]>
1 parent 0760534 commit b771d52

File tree

4 files changed

+8
-312
lines changed

4 files changed

+8
-312
lines changed

examples/malloc_hook.rs

-109
This file was deleted.

proto/perftools.profiles.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// f9f855b960d01b292a3c2642e263e6156d52631e78e0177fe51416ed5bbecc81 proto/profile.proto
22

3+
#[allow(clippy::derive_partial_eq_without_eq)]
34
#[derive(Clone, PartialEq, ::prost::Message)]
45
pub struct Profile {
56
/// A description of the samples associated with each Sample.value.
@@ -65,6 +66,7 @@ pub struct Profile {
6566
pub default_sample_type: i64,
6667
}
6768
/// ValueType describes the semantics and measurement units of a value.
69+
#[allow(clippy::derive_partial_eq_without_eq)]
6870
#[derive(Clone, PartialEq, ::prost::Message)]
6971
pub struct ValueType {
7072
/// Rename it from type to ty to avoid using keyword in Rust.
@@ -80,6 +82,7 @@ pub struct ValueType {
8082
/// context. The program context is typically a stack trace, perhaps
8183
/// augmented with auxiliary information like the thread-id, some
8284
/// indicator of a higher level request being handled etc.
85+
#[allow(clippy::derive_partial_eq_without_eq)]
8386
#[derive(Clone, PartialEq, ::prost::Message)]
8487
pub struct Sample {
8588
/// The ids recorded here correspond to a Profile.location.id.
@@ -99,6 +102,7 @@ pub struct Sample {
99102
#[prost(message, repeated, tag = "3")]
100103
pub label: ::prost::alloc::vec::Vec<Label>,
101104
}
105+
#[allow(clippy::derive_partial_eq_without_eq)]
102106
#[derive(Clone, PartialEq, ::prost::Message)]
103107
pub struct Label {
104108
/// Index into string table
@@ -123,6 +127,7 @@ pub struct Label {
123127
#[prost(int64, tag = "4")]
124128
pub num_unit: i64,
125129
}
130+
#[allow(clippy::derive_partial_eq_without_eq)]
126131
#[derive(Clone, PartialEq, ::prost::Message)]
127132
pub struct Mapping {
128133
/// Unique nonzero id for the mapping.
@@ -162,6 +167,7 @@ pub struct Mapping {
162167
pub has_inline_frames: bool,
163168
}
164169
/// Describes function and line table debug information.
170+
#[allow(clippy::derive_partial_eq_without_eq)]
165171
#[derive(Clone, PartialEq, ::prost::Message)]
166172
pub struct Location {
167173
/// Unique nonzero id for the location. A profile could use
@@ -197,6 +203,7 @@ pub struct Location {
197203
#[prost(bool, tag = "5")]
198204
pub is_folded: bool,
199205
}
206+
#[allow(clippy::derive_partial_eq_without_eq)]
200207
#[derive(Clone, PartialEq, ::prost::Message)]
201208
pub struct Line {
202209
/// The id of the corresponding profile.Function for this line.
@@ -206,6 +213,7 @@ pub struct Line {
206213
#[prost(int64, tag = "2")]
207214
pub line: i64,
208215
}
216+
#[allow(clippy::derive_partial_eq_without_eq)]
209217
#[derive(Clone, PartialEq, ::prost::Message)]
210218
pub struct Function {
211219
/// Unique nonzero id for the function.

src/collector.rs

-87
Original file line numberDiff line numberDiff line change
@@ -360,90 +360,3 @@ mod tests {
360360
}
361361
}
362362
}
363-
364-
#[cfg(test)]
365-
#[cfg(target_os = "linux")]
366-
mod malloc_free_test {
367-
use super::*;
368-
use std::cell::RefCell;
369-
use std::collections::BTreeMap;
370-
use std::ffi::c_void;
371-
372-
#[cfg(not(target_env = "gnu"))]
373-
#[allow(clippy::wrong_self_convention)]
374-
#[allow(non_upper_case_globals)]
375-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void> = None;
376-
377-
#[cfg(target_arch = "riscv64")]
378-
#[allow(clippy::wrong_self_convention)]
379-
#[allow(non_upper_case_globals)]
380-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void> = None;
381-
382-
extern "C" {
383-
#[cfg(target_env = "gnu")]
384-
#[cfg(not(target_arch = "riscv64"))]
385-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void>;
386-
387-
fn malloc(size: usize) -> *mut c_void;
388-
}
389-
390-
thread_local! {
391-
static FLAG: RefCell<bool> = RefCell::new(false);
392-
}
393-
394-
extern "C" fn malloc_hook(size: usize) -> *mut c_void {
395-
unsafe {
396-
__malloc_hook = None;
397-
}
398-
399-
FLAG.with(|flag| {
400-
flag.replace(true);
401-
});
402-
let p = unsafe { malloc(size) };
403-
404-
unsafe {
405-
__malloc_hook = Some(malloc_hook);
406-
}
407-
408-
p
409-
}
410-
411-
#[test]
412-
fn malloc_free() {
413-
let mut collector = Collector::new().unwrap();
414-
let mut real_map = BTreeMap::new();
415-
416-
unsafe {
417-
__malloc_hook = Some(malloc_hook);
418-
}
419-
420-
for item in 0..(1 << 10) * 4 {
421-
for _ in 0..(item % 4) {
422-
collector.add(item, 1).unwrap();
423-
}
424-
}
425-
unsafe {
426-
__malloc_hook = None;
427-
}
428-
429-
FLAG.with(|flag| {
430-
assert!(!*flag.borrow());
431-
});
432-
433-
collector.try_iter().unwrap().for_each(|entry| {
434-
test_utils::add_map(&mut real_map, entry);
435-
});
436-
437-
for item in 0..(1 << 10) * 4 {
438-
let count = (item % 4) as isize;
439-
match real_map.get(&item) {
440-
Some(value) => {
441-
assert_eq!(count, *value);
442-
}
443-
None => {
444-
assert_eq!(count, 0);
445-
}
446-
}
447-
}
448-
}
449-
}

src/profiler.rs

-116
Original file line numberDiff line numberDiff line change
@@ -464,119 +464,3 @@ impl Profiler {
464464
if let Ok(()) = self.data.add(frames, 1) {}
465465
}
466466
}
467-
468-
#[cfg(test)]
469-
#[cfg(target_os = "linux")]
470-
mod tests {
471-
use super::*;
472-
473-
use std::cell::RefCell;
474-
use std::ffi::c_void;
475-
use std::ptr::null_mut;
476-
477-
#[cfg(not(target_env = "gnu"))]
478-
#[allow(clippy::wrong_self_convention)]
479-
#[allow(non_upper_case_globals)]
480-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void> = None;
481-
482-
#[cfg(target_arch = "riscv64")]
483-
#[allow(clippy::wrong_self_convention)]
484-
#[allow(non_upper_case_globals)]
485-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void> = None;
486-
487-
extern "C" {
488-
#[cfg(target_env = "gnu")]
489-
#[cfg(not(target_arch = "riscv64"))]
490-
static mut __malloc_hook: Option<extern "C" fn(size: usize) -> *mut c_void>;
491-
492-
fn malloc(size: usize) -> *mut c_void;
493-
}
494-
495-
thread_local! {
496-
static FLAG: RefCell<bool> = RefCell::new(false);
497-
}
498-
499-
extern "C" fn malloc_hook(size: usize) -> *mut c_void {
500-
unsafe {
501-
__malloc_hook = None;
502-
}
503-
504-
FLAG.with(|flag| {
505-
flag.replace(true);
506-
});
507-
let p = unsafe { malloc(size) };
508-
509-
unsafe {
510-
__malloc_hook = Some(malloc_hook);
511-
}
512-
513-
p
514-
}
515-
516-
#[inline(never)]
517-
fn is_prime_number(v: usize, prime_numbers: &[usize]) -> bool {
518-
if v < 10000 {
519-
let r = prime_numbers.binary_search(&v);
520-
return r.is_ok();
521-
}
522-
523-
for n in prime_numbers {
524-
if v % n == 0 {
525-
return false;
526-
}
527-
}
528-
529-
true
530-
}
531-
532-
#[inline(never)]
533-
fn prepare_prime_numbers() -> Vec<usize> {
534-
// bootstrap: Generate a prime table of 0..10000
535-
let mut prime_number_table: [bool; 10000] = [true; 10000];
536-
prime_number_table[0] = false;
537-
prime_number_table[1] = false;
538-
for i in 2..10000 {
539-
if prime_number_table[i] {
540-
let mut v = i * 2;
541-
while v < 10000 {
542-
prime_number_table[v] = false;
543-
v += i;
544-
}
545-
}
546-
}
547-
let mut prime_numbers = vec![];
548-
for (i, item) in prime_number_table.iter().enumerate().skip(2) {
549-
if *item {
550-
prime_numbers.push(i);
551-
}
552-
}
553-
prime_numbers
554-
}
555-
556-
#[cfg(target_os = "linux")]
557-
#[test]
558-
fn malloc_free() {
559-
trigger_lazy();
560-
561-
let prime_numbers = prepare_prime_numbers();
562-
563-
let mut _v = 0;
564-
565-
unsafe {
566-
__malloc_hook = Some(malloc_hook);
567-
}
568-
for i in 2..50000 {
569-
if is_prime_number(i, &prime_numbers) {
570-
_v += 1;
571-
perf_signal_handler(27, null_mut(), null_mut());
572-
}
573-
}
574-
unsafe {
575-
__malloc_hook = None;
576-
}
577-
578-
FLAG.with(|flag| {
579-
assert!(!*flag.borrow());
580-
});
581-
}
582-
}

0 commit comments

Comments
 (0)