1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ //! This module provides the `CDParser` struct, which is responsible for parsing crash dump files.
16+ //! The parser uses a combination of regex matching and byte offset indexing to efficiently extract
17+ //! information from the crash dump.
18+
1519use crate :: parser:: * ;
1620use grep:: {
1721 regex:: RegexMatcher ,
@@ -80,6 +84,15 @@ pub struct CDParser {
8084}
8185
8286impl CDParser {
87+ /// Creates a new `CDParser` instance.
88+ ///
89+ /// # Arguments
90+ ///
91+ /// * `filepath` - The path to the crash dump file.
92+ ///
93+ /// # Errors
94+ ///
95+ /// Returns an error if the file cannot be opened or the path is invalid.
8396 pub fn new ( filepath : & str ) -> Result < Self , io:: Error > {
8497 let ( filepath, filename) = Self :: split_path_and_filename ( filepath) ?;
8598 let realpath = filepath. join ( & filename) ;
@@ -95,14 +108,16 @@ impl CDParser {
95108 } )
96109 }
97110
98- // really the parse needs to call the grep crate, which then does a simple regex match
99- // the implementation is that we just need to search for the offsets
100- // create the regex that searches for =<section>:<label>
101- // then get all the byte offsets, from the length to each one
102- // using that, map into chunks, and deserialize into the types.rs structs
103- // at the end there will be a big struct that contains all the sections
104- // enrich as needed
105-
111+ /// Builds an index of the crash dump file.
112+ /// The index maps section tags (e.g., `=proc:<0.1.0>`, `=HEAP_INFO:<0.1.0>`) to their corresponding byte offsets and lengths
113+ /// within the file. This allows for efficient retrieval of specific sections later.
114+ ///
115+ /// The index is built by searching the file for lines starting with "=" using a regex.
116+ /// Each match is parsed to extract the tag and optional ID, which are then used to populate the `IndexMap`.
117+ ///
118+ /// # Returns
119+ ///
120+ /// Returns a `Result` containing the `IndexMap` if successful, or an `io::Error` if an error occurred during file processing.
106121 pub fn build_index ( & self ) -> Result < IndexMap , io:: Error > {
107122 let matcher = RegexMatcher :: new ( r"^=.*" ) . unwrap ( ) ;
108123 let mut searcher = SearcherBuilder :: new ( )
@@ -250,6 +265,18 @@ impl CDParser {
250265 Ok ( Text :: from ( "" ) )
251266 }
252267
268+ /// Calculates the group information for each process in the ancestor map.
269+ ///
270+ /// The group information includes the total heap size, binary size, and memory size for each process and its children.
271+ ///
272+ /// # Arguments
273+ ///
274+ /// * `ancestor_map` - A map of process IDs to their children.
275+ /// * `processes` - A map of process IDs to their `ProcInfo`.
276+ ///
277+ /// # Returns
278+ ///
279+ /// Returns a map of process IDs to their `GroupInfo`.
253280 pub fn calculate_group_info (
254281 ancestor_map : & HashMap < String , Vec < String > > ,
255282 processes : & HashMap < String , InfoOrIndex < ProcInfo > > ,
@@ -288,6 +315,17 @@ impl CDParser {
288315 group_info_map
289316 }
290317
318+ /// Creates a table of descendants for each process in the crash dump.
319+ ///
320+ /// The table maps each process ID to a vector of its descendants.
321+ ///
322+ /// # Arguments
323+ ///
324+ /// * `all_processes_info` - A map of all process IDs to their `ProcInfo`.
325+ ///
326+ /// # Returns
327+ ///
328+ /// Returns a map of process IDs to their descendants.
291329 pub fn create_descendants_table (
292330 all_processes_info : & HashMap < String , InfoOrIndex < ProcInfo > > ,
293331 ) -> HashMap < String , Vec < String > > {
0 commit comments