]> git.cworth.org Git - apitrace/commitdiff
cli: Add a simple implementation of "apitrace dump-images"
authorCarl Worth <cworth@cworth.org>
Wed, 28 Mar 2012 01:13:14 +0000 (18:13 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 11 Apr 2012 13:26:50 +0000 (14:26 +0100)
This merely calls out to the existing glretrace command with
appropriate options for generating snapshots. This at least provides
the image-dumping capability within the unified command-line
interface.

In the future, it will likely make sens to make dump-images do things
in-process.

cli/CMakeLists.txt
cli/cli.hpp
cli/cli_dump_images.cpp [new file with mode: 0644]
cli/cli_main.cpp

index e7b8330b49bea81a36a23ee29ac93fee3fd14031..a6fc3a6d3abe6ca3088180cf3566bdf5c7ae0b5d 100644 (file)
@@ -4,6 +4,7 @@ add_executable (apitrace
     cli_diff_state.cpp
     cli_diff_images.cpp
     cli_dump.cpp
+    cli_dump_images.cpp
     cli_pager.cpp
     cli_pickle.cpp
     cli_repack.cpp
index 6c080e86de65683883d520661ecc728ac8a1ae2a..4f3e2b9b36d2f2ad179dac478a9e1d152175f9dc 100644 (file)
@@ -44,6 +44,7 @@ extern const Command diff_command;
 extern const Command diff_state_command;
 extern const Command diff_images_command;
 extern const Command dump_command;
+extern const Command dump_images_command;
 extern const Command pickle_command;
 extern const Command repack_command;
 extern const Command trace_command;
diff --git a/cli/cli_dump_images.cpp b/cli/cli_dump_images.cpp
new file mode 100644 (file)
index 0000000..d42b3f7
--- /dev/null
@@ -0,0 +1,145 @@
+/*********************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * Copyright 2012 Intel Corporation
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
+#include <string.h>
+#include <limits.h> // for CHAR_MAX
+#include <getopt.h>
+#include <iostream>
+
+#include "cli.hpp"
+
+#include "os_string.hpp"
+#include "os_process.hpp"
+
+static const char *synopsis = "Dump frame images obtained from a trace.";
+
+static void
+usage(void)
+{
+    std::cout << "usage apitrace dump-images [OPTIONS] TRACE_FILE\n"
+              << synopsis << "\n"
+        "\n"
+        "    -h, --help           show this help message and exit\n"
+        "        --calls=CALLSET  dump images only for specified calls\n"
+        "                         (default value is \"*/frame\" which\n"
+        "                          which dumps an image for each frame)\n"
+        "    -o, --output=PREFIX  prefix to use in naming output files\n"
+        "                         (default is trace filename without extension)\n"
+        "\n";
+}
+
+enum {
+    CALLS_OPT = CHAR_MAX + 1,
+};
+
+const static char *
+shortOptions = "ho:";
+
+const static struct option
+longOptions[] = {
+    {"help", no_argument, 0, 'h'},
+    {"calls", required_argument, 0, CALLS_OPT},
+    {"output", required_argument, 0, 'o'},
+    {0, 0, 0, 0}
+};
+
+static int
+command(int argc, char *argv[])
+{
+    os::String prefix;
+    const char *calls, *filename, *output = NULL;
+
+    int opt;
+    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
+        switch (opt) {
+        case 'h':
+            usage();
+            return 0;
+        case CALLS_OPT:
+            calls = optarg;
+            break;
+        case 'o':
+            output = optarg;
+            break;
+        default:
+            std::cerr << "error: unexpected option `" << opt << "`\n";
+            usage();
+            return 1;
+        }
+    }
+
+    if (optind >= argc) {
+        std::cerr << "error: apitrace dump-images requires a trace file as an argument.\n";
+        usage();
+        return 1;
+    }
+
+    if (optind < argc - 1) { 
+        std::cerr << "error: apitrace dump-images can accept only a single trace file argument.\n";
+        usage();
+        return 1;
+    }
+
+    filename = argv[optind];
+
+    if (output == NULL) {
+        prefix = filename;
+        prefix.trimDirectory();
+        prefix.trimExtension();
+        output = prefix.str();
+    }
+
+    /* FIXME: It would be cleaner to pull the replaying of the trace
+     * in-process here and generate the images directly. But that
+     * pulls in a non-trivial amount of the existing 'retrace' code,
+     * along with dependencies on GL, etc.
+     *
+     * It will definitely make sense to do that once all that code has
+     * already been pulled in for the "apitrace retrace" (or "apitrace
+     * replay") command. */
+    std::vector<const char *> command;
+    command.push_back("glretrace");
+    command.push_back("-s");
+    command.push_back(output);
+    command.push_back("-S");
+    if (calls)
+        command.push_back(calls);
+    else
+        command.push_back("*/frame");
+    command.push_back(filename);
+    command.push_back(NULL);
+
+    return os::execute((char * const *)&command[0]);
+}
+
+const Command dump_images_command = {
+    "dump-images",
+    synopsis,
+    usage,
+    command
+};
index cff6a05de111955323219d8575ba7400d955f174..8c619ba73a6ea7a865d7a14ffabea0b759c21fd8 100644 (file)
@@ -70,6 +70,7 @@ static const Command * commands[] = {
     &diff_state_command,
     &diff_images_command,
     &dump_command,
+    &dump_images_command,
     &pickle_command,
     &repack_command,
     &trace_command,