link_libraries (common)
-add_executable (tracedump tracedump.cpp)
-
-install (TARGETS tracedump RUNTIME DESTINATION bin)
-
##############################################################################
# API tracers
-add_executable (apitrace apitrace.cpp)
+add_executable (apitrace
+ apitrace.cpp
+ apitrace_dump.cpp)
install (TARGETS apitrace RUNTIME DESTINATION bin)
* functionality.
*/
-#include <iostream>
-#include <iomanip>
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
+#include "apitrace_cli.hpp"
#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
+typedef void (*command_usage_t) (const char *argv0);
typedef int (*command_function_t) (int argc, char *argv[], int first_command_arg);
typedef struct {
const char *name;
+ const char *synopsis;
+ command_usage_t usage;
command_function_t function;
- const char *arguments;
- const char *summary;
- const char *documentation;
} Command;
+#define APITRACE_HELP_SYNOPSIS "Print detailed help for the given command."
+
+static void
+apitrace_help_usage(const char *argv0)
+{
+ std::cout << argv0 << " [<command>]"
+ "\n\n\t"
+ APITRACE_HELP_SYNOPSIS
+ "\n\n\t"
+ "Except in this case, where this is all the help you will get."
+ "\n\n";
+}
+
static int
apitrace_help_command(int argc, char *argv[], int first_command_arg);
static Command 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." }
+ { "dump",
+ APITRACE_DUMP_SYNOPSIS,
+ apitrace_dump_usage,
+ apitrace_dump_command },
+ { "help",
+ APITRACE_HELP_SYNOPSIS,
+ apitrace_help_usage,
+ apitrace_help_command }
};
-static void
+void
usage(void)
{
Command *command;
command = &commands[i];
std::cout << " " << std::setw(max_width+2) << command->name
- << " " << command->summary << "\n";
+ << " " << command->synopsis << "\n";
}
std::cout << "\n"
if (strcmp(command_name, command->name) == 0) {
std::cout << "Help for \"apitrace " << command_name << "\":\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";
+ (command->usage) ("apitrace");
return 0;
}
--- /dev/null
+/*********************************************************************
+ *
+ * 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.
+ *
+ *********************************************************************/
+
+#ifndef _APITRACE_CLI_HPP_
+#define _APITRACE_CLI_HPP_
+
+#include <iostream>
+#include <iomanip>
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define APITRACE_DUMP_SYNOPSIS "Dump given trace(s) to standard output."
+
+void
+apitrace_dump_usage(const char *argv0);
+
+int
+apitrace_dump_command(int argc, char *argv[], int first_command_arg);
+
+void
+usage(void);
+
+#endif /* _APITRACE_CLI_HPP_ */
*
**************************************************************************/
-
-/*
- * Simple utility to dump a trace to standard output.
- */
-
-
-#include <string.h>
+#include "apitrace_cli.hpp"
#include "trace_parser.hpp"
-
enum ColorOption {
COLOR_OPTION_NEVER = 0,
COLOR_OPTION_ALWAYS = 1,
static ColorOption color = COLOR_OPTION_AUTO;
-
-static void usage(void) {
- std::cout <<
- "Usage: tracedump [OPTION] [TRACE]...\n"
- "Dump TRACE to standard output.\n"
- "\n"
- " --help display this help and exit\n"
- " --color[=WHEN]\n"
- " --colour[=WHEN] colored syntax highlighting;\n"
- " WHEN is 'always', 'never', or 'auto'\n"
- ;
+void
+apitrace_dump_usage(const char *argv0)
+{
+ std::cout << argv0 << " [OPTIONS] <trace-file>..."
+ "\n\n\t"
+ APITRACE_DUMP_SYNOPSIS
+ "\n\n\t"
+ "Supports the following options:\n\t"
+ "\t--color=<WHEN>\n\t"
+ "\t--colour=<WHEN> Colored syntax highlighting\n\t"
+ "\t WHEN is 'auto', 'always', or 'never'\n";
}
-
-int main(int argc, char **argv)
+int
+apitrace_dump_command(int argc, char *argv[], int first_arg_command)
{
int i;
- for (i = 1; i < argc; ++i) {
+ for (i = first_arg_command; i < argc; ++i) {
const char *arg = argv[i];
if (arg[0] != '-') {
if (!strcmp(arg, "--")) {
break;
- } else if (!strcmp(arg, "--help")) {
- usage();
- return 0;
} else if (!strcmp(arg, "--color=auto") ||
!strcmp(arg, "--colour=auto")) {
color = COLOR_OPTION_AUTO;