Skip to content

Commit 52eba23

Browse files
committed
Add comments on how parsing works
1 parent 69bee86 commit 52eba23

File tree

3 files changed

+348
-86
lines changed

3 files changed

+348
-86
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
3939
- [x] - Viewing individual information for a process
4040

4141
## TODOs
42-
- [ ] - Implement Help Page (when you press `?`, should come up with a list of commands)
42+
### High Priority
4343
- [ ] - Parallelize `CrashDump::from_index_map`
44-
- [ ] - Implement additional information (when you press enter, we should be able to go into the children table)
44+
- [ ] - Add TextView to inspect all output on Stack/Heap/Messages
45+
- [ ] - Implement additional information (when you press enter, we should be able to go into the children table)
4546
- [ ] - Human readable byte sizes (should be in bytes instead of words)
47+
48+
### Future Work
49+
- [ ] - Implement Help Page (when you press `?`, should come up with a list of commands)
4650
- [ ] - Better coloring that just static coloring (we're currently hardcoding a lot of colors, but these should ideally be moved out)
4751
- [ ] - Implement custom sorting for tables
4852
- [ ] - Implement a regex search for processes (current right now you can't search, only scroll down)

src/parser/parser.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
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+
1519
use crate::parser::*;
1620
use grep::{
1721
regex::RegexMatcher,
@@ -80,6 +84,15 @@ pub struct CDParser {
8084
}
8185

8286
impl 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

Comments
 (0)