| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
//bin/true && exec stap -t -g --suppress-time-limits $0 "$@" |
| 4 |
|
| 5 |
// add extra -G parameters to override these test parameters |
| 6 |
global dims = 3; |
| 7 |
global iLimit = 100; |
| 8 |
global jLimit = 100; |
| 9 |
global kLimit = 100; |
| 10 |
global hashmask = 0xFFFFF; |
| 11 |
global randomize = 0; |
| 12 |
global buckets[1000000]; /* <= iLimit * jLimit * kLimit */ |
| 13 |
global bucketCounts; |
| 14 |
|
| 15 |
|
| 16 |
function gimmeHash1:long(a:long) %{ |
| 17 |
STAP_RETVALUE = hash_ix(STAP_ARG_a); |
| 18 |
%} |
| 19 |
function gimmeHash2:long(a:long, b:long) %{ |
| 20 |
STAP_RETVALUE = hash_iix(STAP_ARG_a, STAP_ARG_b); |
| 21 |
%} |
| 22 |
function gimmeHash3:long(a:long, b:long, c:long) %{ |
| 23 |
STAP_RETVALUE = hash_iiix(STAP_ARG_a, STAP_ARG_b, STAP_ARG_c); |
| 24 |
%} |
| 25 |
global stats1[1], stats2[1], stats3[1]; |
| 26 |
probe never |
| 27 |
{ |
| 28 |
stats1[0] <<< 1; |
| 29 |
stats2[0,1] <<< 1; |
| 30 |
stats3[0,1,2] <<< 1; |
| 31 |
println(@count(stats1[0]) + @count(stats2[0,1]) + @count(stats3[0,1,2])) |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
function rnd(x) |
| 36 |
{ |
| 37 |
return (randomize ? randint(1000000) : x) |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
probe begin(0) |
| 42 |
{ |
| 43 |
printf("parameters:\n\tdims=%d hashmask=%x\n", dims, hashmask) |
| 44 |
printf("\tiLimit=%d jLimit=%d kLimit=%d randomize=%d\n", iLimit, jLimit, kLimit, randomize) |
| 45 |
printf("seed=%x\n", %{ stap_hash_seed %}); |
| 46 |
} |
| 47 |
|
| 48 |
probe begin(1) |
| 49 |
{ |
| 50 |
if (dims == 1) { |
| 51 |
for (i=0; i<iLimit; i++) |
| 52 |
buckets[gimmeHash1(rnd(i)) & hashmask] ++; |
| 53 |
} else if (dims == 2) { |
| 54 |
for (i=0; i<iLimit; i++) |
| 55 |
for (j=0; j<jLimit; j++) |
| 56 |
buckets[gimmeHash2(rnd(i),rnd(j)) & hashmask] ++; |
| 57 |
} else if (dims == 3) { |
| 58 |
for (i=0; i<iLimit; i++) |
| 59 |
for (j=0; j<jLimit; j++) |
| 60 |
for (k=0; k<kLimit; k++) |
| 61 |
buckets[gimmeHash3(rnd(i),rnd(j),rnd(k)) & hashmask] ++; |
| 62 |
} else |
| 63 |
error("bad dims"); |
| 64 |
} |
| 65 |
|
| 66 |
probe begin(2) |
| 67 |
{ |
| 68 |
printf("hash value distribution\n"); |
| 69 |
|
| 70 |
bucketsUsed = 0; |
| 71 |
foreach (idx in buckets) { |
| 72 |
bucketsUsed++; |
| 73 |
bucketCounts <<< buckets[idx]; |
| 74 |
} |
| 75 |
/* For a random distribution of entries to buckets, the expected |
| 76 |
fraction of buckets left empty is exp(- #buckets / #entries). |
| 77 |
For example, if the number of entries put into buckets is the |
| 78 |
same as the number of buckets, exp(-1)=~0.37 so about 63% of |
| 79 |
the buckets will be non-empty, many having one entry and some |
| 80 |
having more. |
| 81 |
|
| 82 |
Since the hash function input could be highly structured and |
| 83 |
repetitive, we shouldn't base evenness of distribution of hash |
| 84 |
values on evenness of distribution of input bit patterns. */ |
| 85 |
printf("%d buckets in use\nBucket-population distribution (i.e., #buckets with 1 entry, with 2 entries, etc):\n", |
| 86 |
bucketsUsed); |
| 87 |
print(@hist_linear(bucketCounts, 1, 125, 1)); |
| 88 |
printf("\n"); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
// speed tests |
| 93 |
probe begin(3) |
| 94 |
{ |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
probe begin(99999) { exit() } |