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

Re: [Lost] [Patch] shell: bench-Befehl



Am Samstag, 5. Juli 2008 13:53:06 schrieb Kevin Wolf:
> + shell: bench für Lesebenchmarks auf einer Datei

So ist er besser
Index: trunk/src/modules/c/shell/cmds/bench.c
===================================================================
--- /dev/null
+++ trunk/src/modules/c/shell/cmds/bench.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008 The LOST Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the LOST Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the LOST Project
+ *     and its contributors.
+ * 4. Neither the name of the LOST Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <syscall.h>
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MAX_BLOCK_SIZE 524288
+
+#ifdef CONFIG_SHELL_BUILTIN_ONLY
+    int shell_command_bench(int argc, char* argv[], const char* args)
+#else
+    #define _USE_START_
+    #include "init.h"
+    int main(int argc, char* argv[])
+#endif
+{
+    char buffer[MAX_BLOCK_SIZE];
+    size_t count, n, size, rsize;
+    size_t bs[] = { 524288, 65536, 4096, 512, 0 };
+    int i;
+    FILE* file;
+    uint64_t tick_start, tick_end, diff;
+
+    if (argc != 3) {
+        printf("bench <Datei> <Kilobytes>\n");
+        return -1;
+    }
+
+    char* path = argv[1];
+
+    if (file == NULL) {
+        printf("Konnte '%s' nicht zum lesen oeffnen!\n", path);
+        return EXIT_FAILURE;
+    }
+
+    count = atoi(argv[2]);
+
+    for (i = 0; bs[i]; i++)
+    {
+        n = count * 1024;
+
+        // Wenn das Verhaeltnis mehr als 1:1024 ist, dauert es zu lang
+#if 0
+        if (bs[i] < count) {
+            continue;
+        }
+#endif
+
+        puts("");
+
+        file = fopen(path, "r");
+        tick_start = get_tick_count();
+        while (n) {
+            size = bs[i] > n ? n : bs[i];
+            rsize = fread(buffer, 1, size, file);
+            if (size != rsize) {
+                printf("Lesefehler.\n");
+                break;
+            }
+            n -= rsize;
+
+            if (n % 65536 == 0) {
+                tick_end = get_tick_count();
+                diff = (tick_end - tick_start);
+                if (diff == 0) {
+                    printf("\rBlockgroesse: %6d; %5d/%5d kB uebrig;"
+                        " Rate: -- Byte/s [%lld s] ",
+                        bs[i], n / 1024, count,
+                        diff / 1000000);
+                } else {
+                    printf("\rBlockgroesse: %6d; %5d/%5d kB uebrig;"
+                        " Rate: %10lld Byte/s [%lld s] ",
+                        bs[i], n / 1024, count,
+                        ((uint64_t) count * 1024 - n) * 1000000 / diff,
+                        diff / 1000000);
+                }
+            }
+        }
+
+        fclose(file);
+    }
+    puts("");
+
+    return EXIT_SUCCESS;
+}
Index: trunk/src/modules/c/shell/shell.c
===================================================================
--- trunk.orig/src/modules/c/shell/shell.c
+++ trunk/src/modules/c/shell/shell.c
@@ -98,7 +98,8 @@ shell_command_t shell_commands[] = {
     {"cp",          &shell_command_cp},
     {"ln",          &shell_command_ln},
     {"rm",          &shell_command_rm},
-    {"stat",        &shell_command_stat}
+    {"stat",        &shell_command_stat},
+    {"bench",       &shell_command_bench},
 #endif
 };
 
Index: trunk/src/modules/c/shell/shell.h
===================================================================
--- trunk.orig/src/modules/c/shell/shell.h
+++ trunk/src/modules/c/shell/shell.h
@@ -66,6 +66,7 @@ int shell_command_set(int argc, char* ar
     int shell_command_ln(int argc, char* argv[], const char* args);
     int shell_command_rm(int argc, char* argv[], const char* args);
     int shell_command_stat(int argc, char* argv[], const char* args);
+    int shell_command_bench(int argc, char* argv[], const char* args);
 #endif
 
 #endif