11use ffikit:: Signal ;
22use pyroscope:: backend:: Tag ;
3- use pyroscope:: PyroscopeAgent ;
43use pyroscope:: pyroscope:: ReportEncoding ;
4+ use pyroscope:: PyroscopeAgent ;
55use pyroscope_pyspy:: { pyspy_backend, PyspyConfig } ;
66use std:: collections:: hash_map:: DefaultHasher ;
77use std:: ffi:: CStr ;
@@ -15,22 +15,22 @@ pub extern "C" fn initialize_logging(logging_level: u32) -> bool {
1515 // Force rustc to display the log messages in the console.
1616 match logging_level {
1717 50 => {
18- std:: env:: set_var ( "RUST_LOG" , "off" ) ;
18+ unsafe { std:: env:: set_var ( "RUST_LOG" , "off" ) } ;
1919 }
2020 40 => {
21- std:: env:: set_var ( "RUST_LOG" , "error" ) ;
21+ unsafe { std:: env:: set_var ( "RUST_LOG" , "error" ) } ;
2222 }
2323 30 => {
24- std:: env:: set_var ( "RUST_LOG" , "warn" ) ;
24+ unsafe { std:: env:: set_var ( "RUST_LOG" , "warn" ) } ;
2525 }
2626 20 => {
27- std:: env:: set_var ( "RUST_LOG" , "info" ) ;
27+ unsafe { std:: env:: set_var ( "RUST_LOG" , "info" ) } ;
2828 }
2929 10 => {
30- std:: env:: set_var ( "RUST_LOG" , "debug" ) ;
30+ unsafe { std:: env:: set_var ( "RUST_LOG" , "debug" ) } ;
3131 }
3232 _ => {
33- std:: env:: set_var ( "RUST_LOG" , "debug" ) ;
33+ unsafe { std:: env:: set_var ( "RUST_LOG" , "debug" ) } ;
3434 }
3535 }
3636
@@ -41,21 +41,11 @@ pub extern "C" fn initialize_logging(logging_level: u32) -> bool {
4141
4242#[ no_mangle]
4343pub extern "C" fn initialize_agent (
44- application_name : * const c_char ,
45- server_address : * const c_char ,
46- auth_token : * const c_char ,
47- basic_auth_username : * const c_char ,
48- basic_auth_password : * const c_char ,
49- sample_rate : u32 ,
50- detect_subprocesses : bool ,
51- oncpu : bool ,
52- gil_only : bool ,
53- report_pid : bool ,
54- report_thread_id : bool ,
55- report_thread_name : bool ,
56- tags : * const c_char ,
57- tenant_id : * const c_char ,
58- http_headers_json : * const c_char ,
44+ application_name : * const c_char , server_address : * const c_char , auth_token : * const c_char ,
45+ basic_auth_username : * const c_char , basic_auth_password : * const c_char , sample_rate : u32 ,
46+ detect_subprocesses : bool , oncpu : bool , gil_only : bool , report_pid : bool ,
47+ report_thread_id : bool , report_thread_name : bool , tags : * const c_char ,
48+ tenant_id : * const c_char , http_headers_json : * const c_char , line_no : LineNo
5949) -> bool {
6050 // Initialize FFIKit
6151 let recv = ffikit:: initialize_ffi ( ) . unwrap ( ) ;
@@ -117,6 +107,7 @@ pub extern "C" fn initialize_agent(
117107 . detect_subprocesses ( detect_subprocesses)
118108 . oncpu ( oncpu)
119109 . native ( false )
110+ . line_no ( line_no. into ( ) )
120111 . gil_only ( gil_only) ;
121112
122113 // Report the PID.
@@ -162,17 +153,15 @@ pub extern "C" fn initialize_agent(
162153 Ok ( http_headers) => {
163154 agent_builder = agent_builder. http_headers ( http_headers) ;
164155 }
165- Err ( e) => {
166- match e {
167- pyroscope:: PyroscopeError :: Json ( e) => {
168- log:: error!( target: LOG_TAG , "parse_http_headers_json error {}" , e) ;
169- }
170- pyroscope:: PyroscopeError :: AdHoc ( e) => {
171- log:: error!( target: LOG_TAG , "parse_http_headers_json {}" , e) ;
172- }
173- _ => { }
156+ Err ( e) => match e {
157+ pyroscope:: PyroscopeError :: Json ( e) => {
158+ log:: error!( target: LOG_TAG , "parse_http_headers_json error {}" , e) ;
174159 }
175- }
160+ pyroscope:: PyroscopeError :: AdHoc ( e) => {
161+ log:: error!( target: LOG_TAG , "parse_http_headers_json {}" , e) ;
162+ }
163+ _ => { }
164+ } ,
176165 }
177166
178167 // Build the agent.
@@ -291,3 +280,21 @@ fn string_to_tags<'a>(tags: &'a str) -> Vec<(&'a str, &'a str)> {
291280
292281 tags_vec
293282}
283+
284+ #[ repr( C ) ]
285+ #[ derive( Debug ) ]
286+ pub enum LineNo {
287+ LastInstruction = 0 ,
288+ First = 1 ,
289+ NoLine = 2 ,
290+ }
291+
292+ impl Into < pyroscope_pyspy:: LineNo > for LineNo {
293+ fn into ( self ) -> pyroscope_pyspy:: LineNo {
294+ match self {
295+ LineNo :: LastInstruction => pyroscope_pyspy:: LineNo :: LastInstruction ,
296+ LineNo :: First => pyroscope_pyspy:: LineNo :: First ,
297+ LineNo :: NoLine => pyroscope_pyspy:: LineNo :: NoLine ,
298+ }
299+ }
300+ }
0 commit comments