From 05e5db0f0a8e75de68f8baa3a0b59bf398caebf6 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 18 Jan 2018 17:09:09 +0000 Subject: Add CLI tool for loading profiling aptures Captures of profiling data are saved in a binary format, and we need a tool that can load them and turn them into user readable (or machine readable) data. --- tools/Makefile.am.inc | 14 +++++++++ tools/eos-profile-tool/eos-profile-cmd-help.c | 27 ++++++++++++++++++ tools/eos-profile-tool/eos-profile-cmds.h | 26 +++++++++++++++++ tools/eos-profile-tool/eos-profile-main.c | 41 +++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 tools/eos-profile-tool/eos-profile-cmd-help.c create mode 100644 tools/eos-profile-tool/eos-profile-cmds.h create mode 100644 tools/eos-profile-tool/eos-profile-main.c (limited to 'tools') diff --git a/tools/Makefile.am.inc b/tools/Makefile.am.inc index 8f0015c..c2db497 100644 --- a/tools/Makefile.am.inc +++ b/tools/Makefile.am.inc @@ -41,3 +41,17 @@ dist_commands_DATA = \ $(NULL) EXTRA_DIST += $(tools_test_modules) + +bin_PROGRAMS = \ + eos-profile \ + $(NULL) + +eos_profile_SOURCES = \ + tools/eos-profile-tool/eos-profile-main.c \ + tools/eos-profile-tool/eos-profile-cmds.h \ + tools/eos-profile-tool/eos-profile-cmd-help.c \ + $(NULL) + +eos_profile_CPPFLAGS = @EOS_SDK_CFLAGS@ -DG_LOG_DOMAIN=\"EosProfile\" +eos_profile_CFLAGS = $(AM_CFLAGS) +eos_profile_LDADD = $(top_builddir)/libendless-@EOS_SDK_API_VERSION@.la @EOS_SDK_LIBS@ diff --git a/tools/eos-profile-tool/eos-profile-cmd-help.c b/tools/eos-profile-tool/eos-profile-cmd-help.c new file mode 100644 index 0000000..88f8b4e --- /dev/null +++ b/tools/eos-profile-tool/eos-profile-cmd-help.c @@ -0,0 +1,27 @@ +#include "config.h" + +#include + +gboolean +eos_profile_cmd_help_parse_args (int argc, + char **argv) +{ + return TRUE; +} + +int +eos_profile_cmd_help_main (void) +{ + g_print ( + "eos-profile\n" + "\n" + "Usage: eos-profile [OPTIONS...]\n" + "\n" + "Examples:\n" + "\n" + " eos-profile help - This help screen\n" + "\n" + ); + + return 0; +} diff --git a/tools/eos-profile-tool/eos-profile-cmds.h b/tools/eos-profile-tool/eos-profile-cmds.h new file mode 100644 index 0000000..f06781c --- /dev/null +++ b/tools/eos-profile-tool/eos-profile-cmds.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +typedef gboolean (* EosProfileCmdParseArgs) (int argc, char **argv); +typedef int (* EosProfileCmdMain) (void); + +gboolean eos_profile_cmd_help_parse_args (int argc, char **argv); +int eos_profile_cmd_help_main (void); + +const struct { + const char *name; + const char *description; + + EosProfileCmdParseArgs parse_args; + EosProfileCmdMain main; +} profile_commands[] = { + { + .name = "help", + .description = "Prints help", + .parse_args = eos_profile_cmd_help_parse_args, + .main = eos_profile_cmd_help_main, + }, + + { NULL, }, +}; diff --git a/tools/eos-profile-tool/eos-profile-main.c b/tools/eos-profile-tool/eos-profile-main.c new file mode 100644 index 0000000..4b76870 --- /dev/null +++ b/tools/eos-profile-tool/eos-profile-main.c @@ -0,0 +1,41 @@ +#include "config.h" + +#include +#include +#include + +#include + +#include "eos-profile-cmds.h" + +static gboolean opt_cmd = FALSE; + +int +main (int argc, + char *argv[]) +{ + const char *cmd = NULL; + + if (argc < 2) + cmd = "help"; + else + cmd = argv[1]; + + for (int i = 0; i < G_N_ELEMENTS (profile_commands); i++) + { + if (g_strcmp0 (cmd, profile_commands[i].name) == 0) + { + argc -= 1; + argv += 1; + + if (!profile_commands[i].parse_args (argc, argv)) + return EXIT_FAILURE; + + return profile_commands[i].main (); + } + } + + g_printerr ("Usage: eos-profile [OPTIONS...]\n"); + + return EXIT_FAILURE; +} -- cgit v1.2.3