diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 140: Main, Options: Add support for loading the list of benchmark to run from a file.

Message ID 20110922105215.18991.5611.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org Sept. 22, 2011, 10:52 a.m. UTC
------------------------------------------------------------
revno: 140
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Tue 2011-09-20 15:52:21 +0300
message:
  Main,Options: Add support for loading the list of benchmark to run from a file.
modified:
  src/main.cpp
  src/options.cpp
  src/options.h


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/main.cpp'
--- src/main.cpp	2011-09-12 16:08:24 +0000
+++ src/main.cpp	2011-09-20 12:52:21 +0000
@@ -29,6 +29,7 @@ 
 #include "util.h"
 
 #include <iostream>
+#include <fstream>
 
 #if USE_GL
 #include "canvas-x11-glx.h"
@@ -85,6 +86,31 @@ 
 }
 
 void
+add_custom_benchmarks_from_files(vector<Benchmark *> &benchmarks)
+{
+    for (vector<string>::const_iterator iter = Options::benchmark_files.begin();
+         iter != Options::benchmark_files.end();
+         iter++)
+    {
+        std::ifstream ifs(iter->c_str());
+
+        if (!ifs.fail()) {
+            std::string line;
+
+            while (getline(ifs, line)) {
+                if (!line.empty())
+                    benchmarks.push_back(new Benchmark(line));
+            }
+        }
+        else {
+            Log::error("Cannot open benchmark file %s\n",
+                       iter->c_str());
+        }
+
+    }
+}
+
+void
 add_and_register_scenes(vector<Scene*>& scenes, Canvas& canvas)
 {
     scenes.push_back(new SceneDefaultOptions(canvas));
@@ -263,10 +289,12 @@ 
     // Add the benchmarks to run
     vector<Benchmark *> benchmarks;
 
-    if (Options::benchmarks.empty())
+    if (!Options::benchmarks.empty())
+        add_custom_benchmarks(benchmarks);
+    else if (!Options::benchmark_files.empty())
+        add_custom_benchmarks_from_files(benchmarks);
+    else
         add_default_benchmarks(benchmarks);
-    else
-        add_custom_benchmarks(benchmarks);
 
     Log::info("=======================================================\n");
     Log::info("    glmark2 %s\n", GLMARK_VERSION);

=== modified file 'src/options.cpp'
--- src/options.cpp	2011-09-20 09:45:24 +0000
+++ src/options.cpp	2011-09-20 12:52:21 +0000
@@ -32,6 +32,7 @@ 
 #include "log.h"
 
 std::vector<std::string> Options::benchmarks;
+std::vector<std::string> Options::benchmark_files;
 bool Options::validate = false;
 bool Options::swap_buffers = true;
 std::pair<int,int> Options::size(800, 600);
@@ -42,6 +43,7 @@ 
 
 static struct option long_options[] = {
     {"benchmark", 1, 0, 0},
+    {"benchmark-file", 1, 0, 0},
     {"validate", 0, 0, 0},
     {"no-swap-buffers", 0, 0, 0},
     {"size", 1, 0, 0},
@@ -88,6 +90,8 @@ 
            "Options:\n"
            "  -b, --benchmark BENCH  A benchmark to run: 'scene(:opt1=val1)*'\n"
            "                         (the option can be used multiple times)\n"
+           "  -f, --benchmark-file F Load benchmarks to run from a file containing a\n"
+           "                         list of benchmark descriptions (one per line)"
            "      --validate         Run a quick output validation test instead of \n"
            "                         running the benchmarks\n"
            "      --no-swap-buffers  Don't update the canvas by swapping the front and\n"
@@ -109,7 +113,7 @@ 
         int c;
         const char *optname = "";
 
-        c = getopt_long(argc, argv, "b:s:ldh",
+        c = getopt_long(argc, argv, "b:f:s:ldh",
                         long_options, &option_index);
         if (c == -1)
             break;
@@ -121,6 +125,8 @@ 
 
         if (c == 'b' || !strcmp(optname, "benchmark"))
             Options::benchmarks.push_back(optarg);
+        else if (c == 'f' || !strcmp(optname, "benchmark-file"))
+            Options::benchmark_files.push_back(optarg);
         else if (!strcmp(optname, "validate"))
             Options::validate = true;
         else if (!strcmp(optname, "no-swap-buffers"))

=== modified file 'src/options.h'
--- src/options.h	2011-09-20 09:45:24 +0000
+++ src/options.h	2011-09-20 12:52:21 +0000
@@ -32,6 +32,7 @@ 
     static void print_help();
 
     static std::vector<std::string> benchmarks;
+    static std::vector<std::string> benchmark_files;
     static bool validate;
     static bool swap_buffers;
     static std::pair<int,int> size;