From: Benjamin Poirier Date: Thu, 26 Nov 2009 18:43:30 +0000 (-0500) Subject: Make option type OPTIONAL_ARG available X-Git-Tag: v0.12.26~21 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=49c335f194a889e54de18abf4c11d135ed6b6a0e;p=lttv.git Make option type OPTIONAL_ARG available These options are not be supported by Lttv and will be ignored (with a warning message). Signed-off-by: Benjamin Poirier --- diff --git a/lttv/lttv/sync/event_analysis_eval.c b/lttv/lttv/sync/event_analysis_eval.c index 29b1b449..3c3f8636 100644 --- a/lttv/lttv/sync/event_analysis_eval.c +++ b/lttv/lttv/sync/event_analysis_eval.c @@ -150,7 +150,6 @@ static AnalysisModule analysisModuleEval= { static ModuleOption optionEvalRttFile= { .longName= "eval-rtt-file", .hasArg= REQUIRED_ARG, - {.arg= NULL}, .optionHelp= "specify the file containing RTT information", .argHelp= "FILE", }; diff --git a/lttv/lttv/sync/event_processing.h b/lttv/lttv/sync/event_processing.h index 34ea8001..2ac26ae2 100644 --- a/lttv/lttv/sync/event_processing.h +++ b/lttv/lttv/sync/event_processing.h @@ -33,9 +33,9 @@ typedef struct char* name; void (*initProcessing)(struct _SyncState* const syncStateLttv, ...); - void (*destroyProcessing)(struct _SyncState* const syncState); void (*finalizeProcessing)(struct _SyncState* const syncState); void (*printProcessingStats)(struct _SyncState* const syncState); + void (*destroyProcessing)(struct _SyncState* const syncState); GraphFunctions graphFunctions; } ProcessingModule; diff --git a/lttv/lttv/sync/sync_chain.c b/lttv/lttv/sync/sync_chain.c index e6541597..0d9773fa 100644 --- a/lttv/lttv/sync/sync_chain.c +++ b/lttv/lttv/sync/sync_chain.c @@ -122,3 +122,19 @@ gint gcfCompareAnalysis(gconstpointer a, gconstpointer b) return strncmp(analysisModule->name, name, strlen(analysisModule->name) + 1); } + + +/* + * A GFunc for g_queue_foreach() + * + * Concatenate analysis module names. + * + * Args: + * data: AnalysisModule* + * user_data: GString*, concatenated names + */ +void gfAppendAnalysisName(gpointer data, gpointer user_data) +{ + g_string_append((GString*) user_data, ((AnalysisModule*) data)->name); + g_string_append((GString*) user_data, ", "); +} diff --git a/lttv/lttv/sync/sync_chain.h b/lttv/lttv/sync/sync_chain.h index 852e8e4a..d187b304 100644 --- a/lttv/lttv/sync/sync_chain.h +++ b/lttv/lttv/sync/sync_chain.h @@ -43,18 +43,18 @@ typedef struct _SyncState typedef struct { + const char shortName; const char* longName; enum { NO_ARG, REQUIRED_ARG, - //OPTIONAL_ARG, // Not yet implemented because not supported by LTTV + OPTIONAL_ARG, HAS_ARG_COUNT // This must be the last field } hasArg; - union - { - bool present; - const char* arg; - }; + bool present; + // in the case of OPTIONAL_ARG, arg can be initialized to a default value. + // If an argument is present, arg will be modified + const char* arg; const char* optionHelp; const char* argHelp; } ModuleOption; @@ -71,5 +71,6 @@ void timeDiff(struct timeval* const end, const struct timeval* const start); gint gcfCompareProcessing(gconstpointer a, gconstpointer b); gint gcfCompareMatching(gconstpointer a, gconstpointer b); gint gcfCompareAnalysis(gconstpointer a, gconstpointer b); +void gfAppendAnalysisName(gpointer data, gpointer user_data); #endif diff --git a/lttv/lttv/sync/sync_chain_lttv.c b/lttv/lttv/sync/sync_chain_lttv.c index 5dd10bf9..bbd2b3aa 100644 --- a/lttv/lttv/sync/sync_chain_lttv.c +++ b/lttv/lttv/sync/sync_chain_lttv.c @@ -40,28 +40,22 @@ static void init(); static void destroy(); -static void gfAppendAnalysisName(gpointer data, gpointer user_data); static void gfAddModuleOption(gpointer data, gpointer user_data); static void gfRemoveModuleOption(gpointer data, gpointer user_data); -static char* argHelpNone= "none"; static ModuleOption optionSync= { .longName= "sync", .hasArg= NO_ARG, - {.present= false}, .optionHelp= "synchronize the time between the traces", }; -static char graphsDir[20]; static ModuleOption optionSyncStats= { .longName= "sync-stats", .hasArg= NO_ARG, - {.present= false}, .optionHelp= "print statistics about the time synchronization", }; static ModuleOption optionSyncNull= { .longName= "sync-null", .hasArg= NO_ARG, - {.present= false}, .optionHelp= "read the events but do not perform any processing", }; static GString* analysisModulesNames; @@ -73,15 +67,16 @@ static ModuleOption optionSyncAnalysis= { static ModuleOption optionSyncGraphs= { .longName= "sync-graphs", .hasArg= NO_ARG, - {.present= false}, .optionHelp= "output gnuplot graph showing synchronization points", }; +static char graphsDir[20]; static ModuleOption optionSyncGraphsDir= { .longName= "sync-graphs-dir", .hasArg= REQUIRED_ARG, .optionHelp= "specify the directory where to store the graphs", }; + /* * Module init function * @@ -100,7 +95,7 @@ static void init() g_debug("Sync init"); g_assert(g_queue_get_length(&analysisModules) > 0); - optionSyncAnalysis.arg = ((AnalysisModule*) + optionSyncAnalysis.arg= ((AnalysisModule*) g_queue_peek_head(&analysisModules))->name; analysisModulesNames= g_string_new(""); g_queue_foreach(&analysisModules, &gfAppendAnalysisName, @@ -125,7 +120,6 @@ static void init() g_queue_push_head(&moduleOptions, &optionSync); g_queue_foreach(&moduleOptions, &gfAddModuleOption, NULL); - } @@ -320,22 +314,6 @@ void syncTraceset(LttvTracesetContext* const traceSetContext) } -/* - * A GFunc for g_queue_foreach() - * - * Concatenate analysis module names. - * - * Args: - * data: AnalysisModule* - * user_data: GString*, concatenated names - */ -static void gfAppendAnalysisName(gpointer data, gpointer user_data) -{ - g_string_append((GString*) user_data, ((AnalysisModule*) data)->name); - g_string_append((GString*) user_data, ", "); -} - - /* * A GFunc for g_queue_foreach() * @@ -345,18 +323,33 @@ static void gfAppendAnalysisName(gpointer data, gpointer user_data) */ static void gfAddModuleOption(gpointer data, gpointer user_data) { - ModuleOption* option; + ModuleOption* option= data; LttvOptionType conversion[]= { [NO_ARG]= LTTV_OPT_NONE, + [OPTIONAL_ARG]= LTTV_OPT_NONE, [REQUIRED_ARG]= LTTV_OPT_STRING, }; + size_t fieldOffset[]= { + [NO_ARG]= offsetof(ModuleOption, present), + [REQUIRED_ARG]= offsetof(ModuleOption, arg), + }; + static const char* argHelpNone= "none"; g_assert_cmpuint(sizeof(conversion) / sizeof(*conversion), ==, HAS_ARG_COUNT); - option= (ModuleOption*) data; - lttv_option_add(option->longName, '\0', option->optionHelp, - option->argHelp ? option->argHelp : argHelpNone, - conversion[option->hasArg], &option->arg, NULL, NULL); + if (option->hasArg == OPTIONAL_ARG) + { + g_warning("Parameters with optional arguments not supported by the " + "lttv option scheme, parameter '%s' will not be available", + option->longName); + } + else + { + lttv_option_add(option->longName, '\0', option->optionHelp, + option->argHelp ? option->argHelp : argHelpNone, + conversion[option->hasArg], (void*) option + fieldOffset[option->hasArg], + NULL, NULL); + } }