]> sourceware.org Git - systemtap.git/commitdiff
PR19802: hashbench.stp
authorFrank Ch. Eigler <fche@redhat.com>
Fri, 18 Mar 2016 01:24:50 +0000 (21:24 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Fri, 18 Mar 2016 16:00:11 +0000 (12:00 -0400)
Rework into the beginning of a hash benchmark suite.
The first test is for plotting 1/2/3-d hash value distributions,
with a bunch of modifiable parameters (use stap "-G param=value").

testsuite/systemtap.base/hashbench.stp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 66acca1..5820c9b
@@ -1,44 +1,72 @@
-global iLimit = 2000;
-global jLimit = 70;
-global buckets[140000]; /* iLimit * jLimit */
+#! /bin/sh
+
+//bin/true && exec stap -t -g --suppress-time-limits $0 "$@"
+
+// add extra -G parameters to override these test parameters
+global dims = 3;
+global iLimit = 100;
+global jLimit = 100;
+global kLimit = 100;
+global hashmask = 0xFFFFF;
+global randomize = 0;
+global buckets[1000000]; /* <= iLimit * jLimit * kLimit */
 global bucketCounts;
-global stats[500000];
 
-function gimmeHash:long(a:long, b:long) %{
+
+function gimmeHash1:long(a:long) %{
+    STAP_RETVALUE = hash_ix(STAP_ARG_a);
+%}
+function gimmeHash2:long(a:long, b:long) %{
     STAP_RETVALUE = hash_iix(STAP_ARG_a, STAP_ARG_b);
 %}
-function gimmeHash64:long(a:long) %{
-    STAP_RETVALUE = hash_64(STAP_ARG_a, 32);
+function gimmeHash3:long(a:long, b:long, c:long) %{
+    STAP_RETVALUE = hash_iiix(STAP_ARG_a, STAP_ARG_b, STAP_ARG_c);
 %}
+global stats1[1], stats2[1], stats3[1];
+probe never
+{
+  stats1[0] <<< 1;
+  stats2[0,1] <<< 1;
+  stats3[0,1,2] <<< 1;
+  println(@count(stats1[0]) + @count(stats2[0,1]) + @count(stats3[0,1,2]))
+}
+
 
-probe begin
+function rnd(x)
 {
-    stats[0,1] <<< 42; /* force the _iix routines to be available */
-    printf("max map entries: %d\n", %{ MAXMAPENTRIES %});
-    printf("hash table bits: %d size: %d\n",
-           %{ HASH_TABLE_BITS %}, %{ HASH_TABLE_SIZE %});
-    printf("seed: %x", %{ stap_hash_seed %});
-    printf(" ignore these: %d %d\n", @count(stats[0,1]), @count(stats[1,0]));
-    if (%{MAXMAPENTRIES%} < iLimit*jLimit) {
-        printf("MAXMAPENTRIES too small, should be at least %d\n",
-               iLimit * jLimit);
-        exit();
-        next;
-    }
-    for (i = 0; i < iLimit; i++) {
-        if (i < 4) { printf("hash(%d,*):", i); }
-        for (j = 0; j < jLimit; j++) {
-            hash = gimmeHash(i, j);
-            if (i < 4) {
-                if ((j % 16) == 0) { printf("\n  %2d:", j); }
-                printf(" %06x", hash);
-            }
-            buckets[hash]++;
-        }
-        if (i < 4) { printf("\n"); }
-    }
-    printf("etc...\n");
-    /* Now buckets[] maps hash value to number of times it came up. */
+  return (randomize ? randint(1000000) : x)
+}
+
+
+probe begin(0)
+{
+      printf("parameters:\n\tdims=%d hashmask=%x\n", dims, hashmask)
+      printf("\tiLimit=%d jLimit=%d kLimit=%d randomize=%d\n", iLimit, jLimit, kLimit, randomize)
+      printf("seed=%x\n", %{ stap_hash_seed %});
+}
+
+probe begin(1)
+{
+    if (dims == 1) {
+      for (i=0; i<iLimit; i++)
+        buckets[gimmeHash1(rnd(i)) & hashmask] ++;
+    } else if (dims == 2) {
+      for (i=0; i<iLimit; i++)
+        for (j=0; j<jLimit; j++)
+          buckets[gimmeHash2(rnd(i),rnd(j)) & hashmask] ++;
+    } else if (dims == 3) {
+      for (i=0; i<iLimit; i++)
+        for (j=0; j<jLimit; j++)
+          for (k=0; k<kLimit; k++)
+            buckets[gimmeHash3(rnd(i),rnd(j),rnd(k)) & hashmask] ++;
+    } else
+      error("bad dims");
+}
+
+probe begin(2)
+{
+    printf("hash value distribution\n");
+
     bucketsUsed = 0;
     foreach (idx in buckets) {
         bucketsUsed++;
@@ -57,13 +85,14 @@ probe begin
     printf("%d buckets in use\nBucket-population distribution (i.e., #buckets with 1 entry, with 2 entries, etc):\n",
            bucketsUsed);
     print(@hist_linear(bucketCounts, 1, 125, 1));
-    print("hash_64 results (32 bits requested):");
-    for (i = 0; i < 300; i++) {
-        if ((i % 8) == 0) {
-            printf("\n %03x: ", i);
-        }
-        printf(" %08x", gimmeHash64(i));
-    }
     printf("\n");
-    exit();
 }
+
+
+// speed tests
+probe begin(3)
+{
+}
+
+
+probe begin(99999) { exit() }
This page took 0.034033 seconds and 5 git commands to generate.