#!/usr/bin/perl

use strict;

open (my $if, "/tmp/xr-prof.txt")
  or die ("Cannot read /tmp/xr-prof.txt: $!\n");

my %info;

while (my $line = <$if>) {
    chomp($line);
    my (undef, undef, $name, $duration) = split (/\s+/, $line);
    # print ("$name: $duration\n");
    if ($info{$name}) {
	my ($calls, $total) = @{ $info{$name} };
	$calls++;
	$total += $duration;
	$info{$name} = [ $calls, $total ];
    } else {
	$info{$name} = [ 1, $duration ];
    }
}

for my $k (sort bytotal keys(%info)) {
    my ($calls, $total) = @{ $info{$k} };
    print ("$k: $total usec\n");
}

sub bytotal {
    my @aa = @{ $info{$a} };
    my @bb = @{ $info{$b} };
    return ($bb[1] <=> $aa[1]);
}
			       
