diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-10-14 13:54:04 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-10-14 13:54:04 (GMT) |
commit | e505ea74b63394100f47233295f0a1835ffb99c2 (patch) | |
tree | 8ed09728aff7763ae0e55226090cfa71a7d419a9 /plugins/devdbg | |
parent | fc010082fcc5371ff198b5b3321eb81fbe2a6013 (diff) |
Refined measures of elapsed time.
Diffstat (limited to 'plugins/devdbg')
-rw-r--r-- | plugins/devdbg/speed.c | 187 | ||||
-rw-r--r-- | plugins/devdbg/speed.h | 3 |
2 files changed, 166 insertions, 24 deletions
diff --git a/plugins/devdbg/speed.c b/plugins/devdbg/speed.c index f9fccfe..935fbd9 100644 --- a/plugins/devdbg/speed.c +++ b/plugins/devdbg/speed.c @@ -24,39 +24,46 @@ #include "speed.h" +#include <assert.h> #include <malloc.h> -#include <time.h> +#include <string.h> #include <sys/time.h> -#include <sys/resource.h> +#include <i18n.h> + + +#include <common/extstr.h> #include <plugins/plugin-def.h> DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("Speed Measure", "Tracks to time spent for disassembling code", "0.1.0", + PGA_FORMAT_ANALYSIS_STARTED,PGA_FORMAT_ANALYSIS_ENDED, + PGA_FORMAT_POST_ANALYSIS_STARTED, PGA_FORMAT_POST_ANALYSIS_ENDED, PGA_DISASSEMBLY_STARTED, PGA_DISASSEMBLY_ENDED); /* Mémorisation des résultats de chronométrages */ typedef struct _speed_measure { - clock_t points[2]; /* Points de mesure successifs */ unsigned long usages[2]; /* Taux d'utilisation du CPU */ } speed_measure; +/* Affiche une mesure de temps écoulé. */ +static void show_elapsed_time(const GPluginModule *, const char *, const speed_measure *); + + /****************************************************************************** * * * Paramètres : plugin = greffon à manipuler. * -* action = type d'action attendue. * -* binary = binaire dont le contenu est en cours de traitement.* -* status = barre de statut à tenir informée. * -* context = contexte de désassemblage. * +* title = désignation humaine de la mesure menée. * +* measure = mesure de temps écoulé. * * * -* Description : Exécute une action pendant un désassemblage de binaire. * +* Description : Affiche une mesure de temps écoulé. * * * * Retour : - * * * @@ -64,23 +71,158 @@ typedef struct _speed_measure * * ******************************************************************************/ -G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *plugin, PluginAction action, GLoadedBinary *binary, GtkStatusStack *status, GProcContext *context) +static void show_elapsed_time(const GPluginModule *plugin, const char *title, const speed_measure *measure) +{ + char *tmp; /* Construction temporaire */ + double seconds; /* Secondes écoulées */ + unsigned long minutes; /* Minutes écoulées */ + unsigned long hours; /* Heures écoulées */ + char *msg; /* Message à faire passer */ + + tmp = NULL; + + seconds = (double)(measure->usages[1] - measure->usages[0]) / 1000000; + + if (seconds > 60) + { + minutes = seconds / 60; + seconds -= minutes * 60; + } + else + minutes = 0; + + if (minutes > 60) + { + hours = minutes / 60; + minutes %= 60; + } + else + hours = 0; + + msg = strdup(title); + + if (hours > 0) + { + asprintf(&tmp, " %lu", hours); + msg = stradd(msg, tmp); + free(tmp); + + msg = stradd(msg, _("h")); + + } + + if (minutes > 0) + { + asprintf(&tmp, " %lu", minutes); + msg = stradd(msg, tmp); + free(tmp); + + msg = stradd(msg, _("m")); + + } + + if (seconds > 0.01) + { + asprintf(&tmp, " %.2f", seconds); + msg = stradd(msg, tmp); + free(tmp); + + msg = stradd(msg, _("s")); + + } + + if (tmp != NULL) + g_plugin_module_log_simple_message(plugin, LMT_INFO, msg); + + free(msg); + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* action = type d'action attendue. * +* format = format de binaire à manipuler pendant l'opération. * +* gid = groupe de travail dédié. * +* status = barre de statut à tenir informée. * +* * +* Description : Procède à une opération liée à l'analyse d'un format. * +* * +* Retour : Bilan de l'exécution du traitement. * +* * +* Remarques : - * +* * +******************************************************************************/ + +G_MODULE_EXPORT bool handle_binary_format_analysis(const GPluginModule *plugin, PluginAction action, GBinFormat *format, wgroup_id_t gid, GtkStatusStack *status) { speed_measure *measure; /* Suivi des progressions */ + struct timeval point; /* Point de mesure courant */ - void take_measure(clock_t *point, unsigned long *usage) + switch (action) { - struct rusage rusage; /* Notification des usages */ + case PGA_FORMAT_ANALYSIS_STARTED: + case PGA_FORMAT_POST_ANALYSIS_STARTED: + + measure = (speed_measure *)calloc(1, sizeof(speed_measure)); + g_object_set_data(G_OBJECT(format), "speed_measure", measure); + + gettimeofday(&point, NULL); + measure->usages[0] = point.tv_sec * 1000000 + point.tv_usec; + + break; + + case PGA_FORMAT_ANALYSIS_ENDED: + case PGA_FORMAT_POST_ANALYSIS_ENDED: - *point = clock(); + measure = (speed_measure *)g_object_get_data(G_OBJECT(format), "speed_measure"); - getrusage(RUSAGE_THREAD, &rusage); + gettimeofday(&point, NULL); + measure->usages[1] = point.tv_sec * 1000000 + point.tv_usec; - *usage = rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec; - *usage += rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec; + if (action == PGA_FORMAT_ANALYSIS_ENDED) + show_elapsed_time(plugin, _("Whole elapsed time for format analysis:"), measure); + else + show_elapsed_time(plugin, _("Whole elapsed time for format post-analysis:"), measure); + + g_object_set_data(G_OBJECT(format), "speed_measure", NULL); + free(measure); + + break; + + default: + assert(false); + break; } + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* action = type d'action attendue. * +* binary = binaire dont le contenu est en cours de traitement.* +* status = barre de statut à tenir informée. * +* context = contexte de désassemblage. * +* * +* Description : Exécute une action pendant un désassemblage de binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *plugin, PluginAction action, GLoadedBinary *binary, GtkStatusStack *status, GProcContext *context) +{ + speed_measure *measure; /* Suivi des progressions */ + struct timeval point; /* Point de mesure courant */ + switch (action) { case PGA_DISASSEMBLY_STARTED: @@ -88,23 +230,19 @@ G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *plugin, Plu measure = (speed_measure *)calloc(1, sizeof(speed_measure)); g_object_set_data(G_OBJECT(binary), "speed_measure", measure); - take_measure(&measure->points[0], &measure->usages[0]); + gettimeofday(&point, NULL); + measure->usages[0] = point.tv_sec * 1000000 + point.tv_usec; break; - case PGA_DISASSEMBLY_ENDED: measure = (speed_measure *)g_object_get_data(G_OBJECT(binary), "speed_measure"); - take_measure(&measure->points[1], &measure->usages[1]); - -#define SHOW_SPEED(pg, sm, title, p0, p1) \ - g_plugin_module_log_variadic_message(pg, LMT_INFO, title ": %.2g (%.2g)", \ - (double)(sm->points[p1] - sm->points[p0]) / CLOCKS_PER_SEC, \ - (sm->usages[p1] - sm->usages[p0]) / 1000000.0); + gettimeofday(&point, NULL); + measure->usages[1] = point.tv_sec * 1000000 + point.tv_usec; - SHOW_SPEED(plugin, measure, "Whole elapsed time for disassembly", 0, 1); + show_elapsed_time(plugin, _("Whole elapsed time for disassembly:"), measure); g_object_set_data(G_OBJECT(binary), "speed_measure", NULL); free(measure); @@ -112,6 +250,7 @@ G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *plugin, Plu break; default: + assert(false); break; } diff --git a/plugins/devdbg/speed.h b/plugins/devdbg/speed.h index 4367570..e99d81c 100644 --- a/plugins/devdbg/speed.h +++ b/plugins/devdbg/speed.h @@ -30,6 +30,9 @@ +/* Procède à une opération liée à l'analyse d'un format. */ +G_MODULE_EXPORT bool handle_binary_format_analysis(const GPluginModule *, PluginAction, GBinFormat *, wgroup_id_t, GtkStatusStack *); + /* Exécute une action pendant un désassemblage de binaire. */ G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *, PluginAction , GLoadedBinary *, GtkStatusStack *, GProcContext *); |