summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pmcstat
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2014-05-16 03:05:53 +0000
committeremaste <emaste@FreeBSD.org>2014-05-16 03:05:53 +0000
commit0e1c93d3c1a464c1bcbd9ba493241df58a7d10ad (patch)
tree8489ff7f77613986d28986008ff04d8c785fcbfe /usr.sbin/pmcstat
parent1c6f6511c894b7650e784d2a2d97948f99898610 (diff)
downloadFreeBSD-src-0e1c93d3c1a464c1bcbd9ba493241df58a7d10ad.zip
FreeBSD-src-0e1c93d3c1a464c1bcbd9ba493241df58a7d10ad.tar.gz
Speed up pmcstat by improving string hash
In one case generating callgraph output from a 24MB system-wide sampling data file took 17.4 seconds on average. Profiling showed pmcstat spending a lot of time in strcmp, due to hash collisions. Replacing the XOR-only hash with FNV-1a reduces the run time for my test by 40%.
Diffstat (limited to 'usr.sbin/pmcstat')
-rw-r--r--usr.sbin/pmcstat/pmcstat_log.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.sbin/pmcstat/pmcstat_log.c b/usr.sbin/pmcstat/pmcstat_log.c
index f0e4939..40de320 100644
--- a/usr.sbin/pmcstat/pmcstat_log.c
+++ b/usr.sbin/pmcstat/pmcstat_log.c
@@ -307,10 +307,10 @@ pmcstat_stats_reset(int reset_global)
static int
pmcstat_string_compute_hash(const char *s)
{
- int hash;
+ unsigned hash;
- for (hash = 0; *s; s++)
- hash ^= *s;
+ for (hash = 2166136261; *s; s++)
+ hash = (hash ^ *s) * 16777619;
return (hash & PMCSTAT_HASH_MASK);
}
OpenPOWER on IntegriCloud