pub fn sorted_table_lines<'a, K, V>(
    table: impl IntoIterator<Item = (K, &'a V)> + 'a,
) -> (usize, impl Iterator<Item = (String, &'a V)>)
where
    K: Ord + Display + 'a,
    V: Ord + Display + 'a,
{
    let mut entries = table.into_iter().collect::<Vec<_>>();
    // Sort table by count (descending), then the name order (ascending).
    entries.sort_unstable_by(|a, b| a.1.cmp(b.1).reverse().then_with(|| a.0.cmp(&b.0)));
    // Convert counts to `String`s to prepare them for printing and to measure their width.
    let mut entries =
        entries.into_iter().map(|(label, ct)| (label.to_string().to_lowercase(), ct)).peekable();
    // Calculate width for padding the counts.
    let width = entries.peek().map(|(_, b)| b.to_string().len()).unwrap_or_default();

    (width, entries)
}
Returns a tuple containing everything needed to to correctly display a table of counts
(e.g. `opcode_counts`):

1. The number of characters of the highest count, that can be used to right-justify the count
column.

2. The table sorted first by count (descending) and then by label (ascending). The table itself
is an iterator of a tuple (label, count).
crates/core/executor/src/events/utils.rs