From c21919571415ad8a8047744aa5411c7ded696620 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Tue, 5 Dec 2023 17:07:37 -0800 Subject: [PATCH] Sort streams by type in raw view The method minidump::Minidump::all_streams iterates over a HashMap which is documented to return values in an arbitrary order. In the UI, that can be a little confusing, so I added sorting based on the stream type which is an integer value. I chose this order over the names because the more commonly used streams seem to appear first when sorted by type. --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/ui_raw_dump.rs | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36c47d3..d3bb1f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,6 +974,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + [[package]] name = "elementtree" version = "1.2.3" @@ -1637,6 +1643,15 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -1872,6 +1887,7 @@ dependencies = [ "eframe", "egui", "egui_extras", + "itertools", "linked-hash-map", "memmap2 0.5.10", "minidump", diff --git a/Cargo.toml b/Cargo.toml index e7c561e..2e648e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ tracing = { version = "0.1.34", features = ["log"] } tracing-subscriber = "0.3.14" linked-hash-map = "0.5.6" clap = { version = "3.2.15", features = ["derive"] } +itertools = "0.12.0" # generated by 'cargo dist init' [profile.dist] diff --git a/src/ui_raw_dump.rs b/src/ui_raw_dump.rs index fcd1121..bf6b495 100644 --- a/src/ui_raw_dump.rs +++ b/src/ui_raw_dump.rs @@ -2,6 +2,7 @@ use crate::MyApp; use eframe::egui; use egui::{Frame, TextStyle, Ui}; use egui_extras::{Size, TableBuilder}; +use itertools::Itertools; use memmap2::Mmap; use minidump::{format::MINIDUMP_STREAM_TYPE, Minidump}; use num_traits::FromPrimitive; @@ -39,6 +40,7 @@ impl MyApp { } let stream = dump .all_streams() + .sorted_by(|a, b| Ord::cmp(&a.stream_type, &b.stream_type)) .nth(self.raw_dump_ui_state.cur_stream - 1) .and_then(|entry| MINIDUMP_STREAM_TYPE::from_u32(entry.stream_type)); if let Some(stream) = stream { @@ -80,7 +82,11 @@ impl MyApp { ui.separator(); ui.selectable_value(&mut self.raw_dump_ui_state.cur_stream, 0, ""); - for (i, stream) in dump.all_streams().enumerate() { + for (i, stream) in dump + .all_streams() + .sorted_by(|a, b| Ord::cmp(&a.stream_type, &b.stream_type)) + .enumerate() + { use MINIDUMP_STREAM_TYPE::*; let (supported, label) = if let Some(stream_type) = MINIDUMP_STREAM_TYPE::from_u32(stream.stream_type) { @@ -147,7 +153,11 @@ impl MyApp { }); }) .body(|mut body| { - for (i, stream) in dump.all_streams().enumerate() { + for (i, stream) in dump + .all_streams() + .sorted_by(|a, b| Ord::cmp(&a.stream_type, &b.stream_type)) + .enumerate() + { body.row(row_height, |mut row| { row.col(|ui| { ui.centered_and_justified(|ui| {