[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH XTF perf 3/4] time: provide measurement template



The added function measure_performance allows to measure the run time
of a function, by computing the average time it takes to call that
function a given number of retries. The measured total time is returned
in nano seconds. Furthermore, the value is printed via printk in a
fixed format, to allow processing the output further.

This format is, where average-time provides ns with ps granularity:

perf test_name <average-time> ns

Signed-off-by: Norbert Manthey <nmanthey@xxxxxxxxx>

---
 common/time.c      | 36 ++++++++++++++++++++++++++++++++++++
 include/xtf/time.h |  8 +++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/common/time.c b/common/time.c
--- a/common/time.c
+++ b/common/time.c
@@ -192,6 +192,42 @@ void msleep(uint64_t t)
     mspin_sleep(t);
 }
 
+long measure_performance(const char* test_name, const char* function_name,
+                         unsigned long retries, to_be_measured call)
+{
+    struct timeval start, end;
+    int rc = 0;
+
+    printk("Start calling %s %lu times\n", function_name, retries);
+
+    /* Perform all calls, measure start and end time */
+    gettimeofday(&start);
+    for(unsigned long counter = 0; counter < retries; ++ counter)
+    {
+        rc = call();
+    }
+    gettimeofday(&end);
+
+    /* Calculate the total number in nano seconds */
+    long total_ns = (end.sec - start.sec)*1000000000 + (end.nsec - start.nsec);
+    long avg_ns = total_ns / retries;
+    long avg_ps = (total_ns / (retries/1000)) % 1000;
+
+    /* Show the result of the last query */
+    printk("%s last result: %d\n", function_name, rc);
+
+    /* Print average time and total time */
+    printk("Avg %s call time: avg: %ld.%s%ld ns total: %ld ns\n",
+           function_name, avg_ns,
+           avg_ps < 10 ? "0" : (avg_ps < 100 ? "0" : ""), avg_ps, total_ns);
+
+    /* Print performance value */
+    printk("perf %s %ld.%s%ld ns\n", test_name, avg_ns,
+           avg_ps < 10 ? "0" : (avg_ps < 100 ? "0" : ""), avg_ps);
+
+    return total_ns;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/include/xtf/time.h b/include/xtf/time.h
--- a/include/xtf/time.h
+++ b/include/xtf/time.h
@@ -49,10 +49,16 @@ void msleep(uint64_t f);
 
 int gettimeofday(struct timeval *tp);
 
-
 /* This returns the current epoch time */
 #define NOW() current_time()
 
+/* Signature of a function to be called for measurement */
+typedef int (*to_be_measured)(void);
+
+/* Measure the time it takes to call the passed function RETRIES times */
+long measure_performance(const char* test_name, const char* function_name,
+                         unsigned long retries, to_be_measured call);
+
 #endif /* XTF_TIME_H */
 
 /*
-- 
2.7.4




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.