summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2011-10-19 18:02:33 -0700
committerCarl Worth <cworth@cworth.org>2011-10-19 18:04:07 -0700
commit4c348c15f52fae933c1c693627c1dd55608069ba (patch)
tree76e3822cf055a705b11a08d2d0aa68e13a98f46c
parent2f5b1f2477b269eaf4a09464f3c86c65b78603b4 (diff)
Add a top-level apitrace program.
This is intended to eventually be a program which will provide access to all apitrace functionality (tracing, trimming, replaying, analyzing, launch the gui, etc.). To start with it implements only the stub "apitrace help" command so there's not any real functionality here yet.
-rw-r--r--.gitignore1
-rwxr-xr-xCMakeLists.txt4
-rw-r--r--apitrace.cpp174
3 files changed, 178 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 4d3307b..18d8646 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ _CPack_Packages
CMakeCache.txt
CMakeFiles
Makefile
+apitrace
build
cgltrace.cpp
config.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 36fa656..bf0f41c 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -233,8 +233,10 @@ set_target_properties (common PROPERTIES
link_libraries (common)
add_executable (tracedump tracedump.cpp)
-install (TARGETS tracedump RUNTIME DESTINATION bin)
+add_executable (apitrace apitrace.cpp)
+
+install (TARGETS apitrace tracedump RUNTIME DESTINATION bin)
##############################################################################
# API tracers
diff --git a/apitrace.cpp b/apitrace.cpp
new file mode 100644
index 0000000..5aa5a65
--- /dev/null
+++ b/apitrace.cpp
@@ -0,0 +1,174 @@
+/*********************************************************************
+ *
+ * Copyright 2011 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.
+ *
+ *********************************************************************/
+
+
+/*
+ * Top-level application for accessing most all apitrace
+ * functionality.
+ */
+
+#include <iostream>
+#include <iomanip>
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "config.h"
+
+#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
+
+typedef int (*command_function_t) (int argc, char *argv[], int first_command_arg);
+
+typedef struct command {
+ const char *name;
+ command_function_t function;
+ const char *arguments;
+ const char *summary;
+ const char *documentation;
+} command_t;
+
+static int
+apitrace_help_command(int argc, char *argv[], int first_command_arg);
+
+static command_t commands[] = {
+ { "help", apitrace_help_command,
+ "[<command>]",
+ "Print detailed help for the given command.",
+ "\tExcept in this case, where this is all the help you will get." }
+};
+
+static void
+usage(void)
+{
+ command_t *command;
+ int i, max_width = 0;
+
+ std::cout <<
+ "Usage: apitrace <command> [<args> ...]\n\n"
+ "The available commands are as follows:\n\n";
+
+ std::cout << std::setiosflags(std::ios::left);
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ command = &commands[i];
+ if (strlen(command->name) > max_width)
+ max_width = strlen(command->name);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ command = &commands[i];
+
+ std::cout << " " << std::setw(max_width+2) << command->name
+ << " " << command->summary << "\n";
+ }
+
+ std::cout << "\n"
+ "Use \"apitrace help <command>\" for more details on each command.\n";
+}
+
+static int
+apitrace_help_command(int argc, char *argv[], int first_arg_command)
+{
+ command_t *command;
+ int i;
+
+ if(argc == 0) {
+ usage();
+ return 0;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ command = &commands[i];
+
+ if (strcmp(argv[0], command->name) == 0) {
+ std::cout << "Help for \"apitrace " << argv[0] << "\":\n\n";
+ std::cout << command->name;
+ if (command->arguments)
+ std::cout << " " << command->arguments
+ << "\n\n\t" << command->summary;
+ else
+ std::cout << "\t" << command->summary;
+ std::cout << "\n\n" << command->documentation << "\n\n";
+
+ return 0;
+ }
+ }
+
+ std::cerr << "Error: Unknown command: " << argv[0]
+ << " (see \"apitrace help\").\n";
+
+ return 1;
+}
+
+int
+main(int argc, char **argv)
+{
+ const char *command_name = "trace";
+ command_t *command;
+ int i, first_command_arg;
+
+ if (argc == 1) {
+ usage();
+ return 1;
+ }
+
+ for (i = 1; i < argc; ++i) {
+ const char *arg = argv[i];
+
+ if (arg[0] != '-') {
+ break;
+ }
+
+ if (strcmp(arg, "--help") == 0) {
+ return apitrace_help_command (0, NULL, 0);
+ } else {
+ std::cerr << "Error: unknown option " << arg << "\n";
+ usage();
+ return 1;
+ }
+ }
+ first_command_arg = i;
+
+ if (first_command_arg < argc) {
+ command_name = argv[first_command_arg];
+ first_command_arg++;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(commands); i++) {
+ command = &commands[i];
+
+ if (strcmp(command_name, command->name) == 0)
+ return (command->function) (argc, argv, first_command_arg);
+ }
+
+ std::cerr << "Error: unknown command " << command_name
+ << " (see \"apitrace help\").\n";
+
+ return 1;
+}