summaryrefslogtreecommitdiff
path: root/modules/benchmark/bench_util.c
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-08-10 23:11:21 -0500
committerLeandro A. F. Pereira <leandro@hardinfo.org>2019-08-14 20:02:42 -0700
commitd17909c82b03ad0427a285c66766421751546c42 (patch)
tree485588a0822984d437fcd22ed9f23f441760ca72 /modules/benchmark/bench_util.c
parent30508a10bf269e5ca06226fb50c86f5249cc746a (diff)
Benchmark: fixes, user_note, verifiable test data
* fix zlib display order * fix cryptohash MiB/s calculation * revision and params for other benchmarks * allow attaching user note to bench result with -u * don't inlcude the new result value bits if they are empty/invalid in bench_value_to_str(). bench_value_from_str() doesn't need to be modified. * bench_results: clean old result cpu name for x86 * use problem_marker() from dmi_memory to mark old version bench results * benchmark: verifiable test data size and content - The test data benchmark.data is stored in a file that could be edited to change the size or content. /* to guarantee size */ gchar *get_test_data(gsize min_size); /* to checksum content */ char *md5_digest_str(const char *data, unsigned int len); Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/benchmark/bench_util.c')
-rw-r--r--modules/benchmark/bench_util.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/modules/benchmark/bench_util.c b/modules/benchmark/bench_util.c
new file mode 100644
index 00000000..d9e5bc55
--- /dev/null
+++ b/modules/benchmark/bench_util.c
@@ -0,0 +1,58 @@
+
+#include "benchmark.h"
+#include "md5.h"
+
+gchar *get_test_data(gsize min_size) {
+ gchar *bdata_path, *data;
+ gsize data_size;
+
+ gchar *exp_data, *p;
+ gsize sz;
+
+ bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
+ if (!g_file_get_contents(bdata_path, &data, &data_size, NULL)) {
+ g_free(bdata_path);
+ return NULL;
+ }
+
+ if (data_size < min_size) {
+ DEBUG("expanding %lu bytes of test data to %lu bytes", data_size, min_size);
+ exp_data = g_malloc(min_size + 1);
+ memcpy(exp_data, data, data_size);
+ p = exp_data + data_size;
+ sz = data_size;
+ while (sz < (min_size - data_size) ) {
+ memcpy(p, data, data_size);
+ p += data_size;
+ sz += data_size;
+ }
+ strncpy(p, data, min_size - sz);
+ g_free(data);
+ data = exp_data;
+ }
+ g_free(bdata_path);
+
+ return data;
+}
+
+char *digest_to_str(const char *digest, int len) {
+ int max = len * 2;
+ char *ret = malloc(max+1);
+ char *p = ret;
+ memset(ret, 0, max+1);
+ int i = 0;
+ for(; i < len; i++) {
+ unsigned char byte = digest[i];
+ p += sprintf(p, "%02x", byte);
+ }
+ return ret;
+}
+
+char *md5_digest_str(const char *data, unsigned int len) {
+ struct MD5Context ctx;
+ guchar digest[16];
+ MD5Init(&ctx);
+ MD5Update(&ctx, (guchar *)data, len);
+ MD5Final(digest, &ctx);
+ return digest_to_str(digest, 16);
+}