@@ -26,17 +26,23 @@ use serde::{Deserialize, Serialize};
2626pub mod collector;
2727pub mod reporter;
2828
29- // Reporter id is a unique identifier for a reporter.
30- //
31- // It is used to identify the process that sends the execution report.
32- // Because the OS PID is not unique across a single build (PIDs are
33- // recycled), we need to use a new unique identifier to identify the process.
29+ /// Reporter id is a unique identifier for a reporter.
30+ ///
31+ /// It is used to identify the process that sends the execution report.
32+ /// Because the OS PID is not unique across a single build (PIDs are
33+ /// recycled), we need to use a new unique identifier to identify the process.
3434#[ derive( Serialize , Deserialize , Debug , PartialEq , Clone ) ]
3535pub struct ReporterId ( pub u64 ) ;
3636
37+ /// Process id is a OS identifier for a process.
3738#[ derive( Serialize , Deserialize , Debug , PartialEq , Clone ) ]
3839pub struct ProcessId ( pub u32 ) ;
3940
41+ /// Execution is a representation of a process execution.
42+ ///
43+ /// It does not contain information about the outcome of the execution,
44+ /// like the exit code or the duration of the execution. It only contains
45+ /// the information that is necessary to reproduce the execution.
4046#[ derive( Serialize , Deserialize , Debug , PartialEq , Clone ) ]
4147pub struct Execution {
4248 pub executable : PathBuf ,
@@ -45,26 +51,20 @@ pub struct Execution {
4551 pub environment : HashMap < String , String > ,
4652}
4753
48- // Represent a relevant life cycle event of a process.
49- //
50- // Currently, it's only the process life cycle events (start, signal,
51- // terminate), but can be extended later with performance related
52- // events like monitoring the CPU usage or the memory allocation if
53- // this information is available.
54+ /// Represent a relevant life cycle event of a process.
55+ ///
56+ /// In the current implementation, we only have one event, the `Started` event.
57+ /// This event is sent when a process is started. It contains the process id
58+ /// and the execution information.
5459#[ derive( Serialize , Deserialize , Debug , PartialEq , Clone ) ]
55- pub enum Event {
56- Started {
57- pid : ProcessId ,
58- execution : Execution ,
59- } ,
60- Terminated {
61- status : i64 ,
62- } ,
63- Signaled {
64- signal : i32 ,
65- } ,
60+ pub struct Event {
61+ pub pid : ProcessId ,
62+ pub execution : Execution ,
6663}
6764
65+ /// Envelope is a wrapper around the event.
66+ ///
67+ /// It contains the reporter id, the timestamp of the event and the event itself.
6868#[ derive( Serialize , Deserialize , Debug , PartialEq , Clone ) ]
6969pub struct Envelope {
7070 pub rid : ReporterId ,
@@ -82,6 +82,10 @@ impl Envelope {
8282 }
8383 }
8484
85+ /// Read an envelope from a reader using TLV format.
86+ ///
87+ /// The envelope is serialized using JSON and the length of the JSON
88+ /// is written as a 4 byte big-endian integer before the JSON.
8589 pub fn read_from ( reader : & mut impl Read ) -> Result < Self , anyhow:: Error > {
8690 let mut length_bytes = [ 0 ; 4 ] ;
8791 reader. read_exact ( & mut length_bytes) ?;
@@ -94,6 +98,10 @@ impl Envelope {
9498 Ok ( envelope)
9599 }
96100
101+ /// Write an envelope to a writer using TLV format.
102+ ///
103+ /// The envelope is serialized using JSON and the length of the JSON
104+ /// is written as a 4 byte big-endian integer before the JSON.
97105 pub fn write_into ( & self , writer : & mut impl Write ) -> Result < u32 , anyhow:: Error > {
98106 let serialized_envelope = serde_json:: to_string ( & self ) ?;
99107 let bytes = serialized_envelope. into_bytes ( ) ;
0 commit comments