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

[tyndur-devel] [PATCH 2/6] shell: bench -s



+ shell: bench -s macht sehr kurz Reads (16 und 1 Byte), dass man den
  Effekt von Readahead in stdio.h messen kann

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/c/shell/cmds/bench.c   |   45 ++++++++++++++++++++++++++++++-----
 src/modules/c/shell/lang/lang_en.c |    2 +-
 2 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/modules/c/shell/cmds/bench.c b/src/modules/c/shell/cmds/bench.c
index 09493dd..fae16fe 100644
--- a/src/modules/c/shell/cmds/bench.c
+++ b/src/modules/c/shell/cmds/bench.c
@@ -39,9 +39,15 @@
 #include <stdio.h>
 #include <string.h>
 #include <tms.h>
+#include <getopt.h>
 
 #define MAX_BLOCK_SIZE 524288
 
+static void usage(void)
+{
+    printf(TMS(bench_usage, "\nAufruf: bench [-s] <Dateiname> <Kilobytes>\n"));
+}
+
 #ifdef CONFIG_SHELL_BUILTIN_ONLY
     int shell_command_bench(int argc, char* argv[], const char* args)
 #else
@@ -50,24 +56,49 @@
 {
     char buffer[MAX_BLOCK_SIZE];
     size_t count, n, size, rsize;
-    size_t bs[] = { 524288, 65536, 4096, 512, 0 };
+    size_t bs_large[] = { 524288, 65536, 4096, 512, 0 };
+    size_t bs_small[] = { 16, 1, 0 };
+    size_t* bs;
     int i;
+    char* path;
     FILE* file;
     uint64_t tick_start, tick_end, diff;
+    bool small_reads = false;
+
+    optind = 1;
+    while (optind < argc) {
+        int result = getopt(argc, argv, "s");
+        if (result == -1) {
+            break;
+        }
 
-    if (argc != 3) {
-        printf(TMS(bench_usage, "\nAufruf: bench <Dateiname> <Kilobytes>\n"));
-        return -1;
+        switch (result) {
+            case 's':
+                small_reads = true;
+                break;
+            default:
+                usage();
+                return EXIT_FAILURE;
+        }
     }
 
-    char* path = argv[1];
+    if (optind != argc - 2) {
+        usage();
+        return EXIT_FAILURE;
+    }
 
+    path = argv[optind++];
+    count = atoi(argv[optind++]);
 
-    count = atoi(argv[2]);
+    bs = small_reads ? bs_small : bs_large;
 
     for (i = 0; bs[i]; i++)
     {
-        n = ((count + 63) & ~63) * 1024;
+        if (small_reads) {
+            n = count * 1024;
+        } else {
+            n = ((count + 63) & ~63) * 1024;
+        }
 
         puts("");
 
diff --git a/src/modules/c/shell/lang/lang_en.c b/src/modules/c/shell/lang/lang_en.c
index 6a7c050..3366190 100644
--- a/src/modules/c/shell/lang/lang_en.c
+++ b/src/modules/c/shell/lang/lang_en.c
@@ -116,7 +116,7 @@ static const struct tms_strings dict[] = {
 
 
     &__tms_bench_usage,
-    "\nUsage: bench <filename> <kilobytes>\n",
+    "\nUsage: bench [-s] <filename> <kilobytes>\n",
 
     &__tms_bench_opening_error,
     "Couldn't open '%s' for reading!\n",
-- 
1.7.7