@@ -3,54 +3,6 @@ use crate::{error::Result, PyroscopeError};
33
44use std:: collections:: HashMap ;
55
6- // Copyright: https://github.com/cobbinma - https://github.com/YangKeao/pprof-rs/pull/14
7- /// Format application_name with tags.
8- pub fn _merge_tags_with_app_name (
9- application_name : String , tags : HashMap < String , String > ,
10- ) -> Result < String > {
11- let mut tags_vec = tags
12- . into_iter ( )
13- . filter ( |( k, _) | k != "__name__" )
14- . map ( |( k, v) | format ! ( "{}={}" , k, v) )
15- . collect :: < Vec < String > > ( ) ;
16- tags_vec. sort ( ) ;
17- let tags_str = tags_vec. join ( "," ) ;
18-
19- if !tags_str. is_empty ( ) {
20- Ok ( format ! ( "{}{{{}}}" , application_name, tags_str, ) )
21- } else {
22- Ok ( application_name)
23- }
24- }
25-
26- #[ cfg( test) ]
27- mod merge_tags_with_app_name_tests {
28- use std:: collections:: HashMap ;
29-
30- use crate :: utils:: _merge_tags_with_app_name;
31-
32- #[ test]
33- fn merge_tags_with_app_name_with_tags ( ) {
34- let mut tags = HashMap :: new ( ) ;
35- tags. insert ( "env" . to_string ( ) , "staging" . to_string ( ) ) ;
36- tags. insert ( "region" . to_string ( ) , "us-west-1" . to_string ( ) ) ;
37- tags. insert ( "__name__" . to_string ( ) , "reserved" . to_string ( ) ) ;
38- assert_eq ! (
39- _merge_tags_with_app_name( "my.awesome.app.cpu" . to_string( ) , tags) . unwrap( ) ,
40- "my.awesome.app.cpu{env=staging,region=us-west-1}" . to_string( )
41- )
42- }
43-
44- #[ test]
45- fn merge_tags_with_app_name_without_tags ( ) {
46- assert_eq ! (
47- _merge_tags_with_app_name( "my.awesome.app.cpu" . to_string( ) , HashMap :: default ( ) )
48- . unwrap( ) ,
49- "my.awesome.app.cpu" . to_string( )
50- )
51- }
52- }
53-
546/// Format application_name with tags.
557pub fn merge_tags_with_app_name ( application_name : String , tags : Vec < Tag > ) -> Result < String > {
568 // tags empty, return application_name
@@ -74,7 +26,7 @@ pub fn merge_tags_with_app_name(application_name: String, tags: Vec<Tag>) -> Res
7426}
7527
7628#[ cfg( test) ]
77- mod merge_tags_with_app_name_tests_2 {
29+ mod merge_tags_with_app_name_tests {
7830 use crate :: { backend:: Tag , utils:: merge_tags_with_app_name} ;
7931
8032 #[ test]
@@ -123,6 +75,22 @@ mod check_err_tests {
12375 }
12476}
12577
78+ /// libc::epoll_ctl wrapper
79+ pub fn pthread_self ( ) -> Result < u64 > {
80+ let thread_id = check_err ( unsafe { libc:: pthread_self ( ) } ) ?;
81+ Ok ( thread_id)
82+ }
83+
84+ mod pthread_self_tests {
85+ use crate :: utils:: pthread_self;
86+
87+ #[ test]
88+ fn pthread_self_success ( ) {
89+ // This function should always succeeds.
90+ assert ! ( pthread_self( ) . is_ok( ) )
91+ }
92+ }
93+
12694/// Return the current time in seconds.
12795pub fn get_current_time_secs ( ) -> Result < u64 > {
12896 Ok ( std:: time:: SystemTime :: now ( )
0 commit comments