/* Chrysalide - Outil d'analyse de fichiers binaires
* speed.c - mesure de temps d'exécution internes
*
* Copyright (C) 2015-2017 Cyrille Bagard
*
* This file is part of Chrysalide.
*
* Chrysalide is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Chrysalide is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see .
*/
#include "speed.h"
#include
#include
#include
#include
#include
DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("Speed Measure", "Tracks to time spent for disassembling code", "0.1.0",
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;
/******************************************************************************
* *
* Paramètres : plugin = greffon à manipuler. *
* action = type d'action attendue. *
* binary = binaire dont le contenu est en cours de traitement. *
* *
* 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)
{
speed_measure *measure; /* Suivi des progressions */
void take_measure(clock_t *point, unsigned long *usage)
{
struct rusage rusage; /* Notification des usages */
*point = clock();
getrusage(RUSAGE_THREAD, &rusage);
*usage = rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec;
*usage += rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec;
}
switch (action)
{
case PGA_DISASSEMBLY_STARTED:
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]);
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);
SHOW_SPEED(plugin, measure, "Whole elapsed time for disassembly", 0, 1);
g_object_set_data(G_OBJECT(binary), "speed_measure", NULL);
free(measure);
break;
default:
break;
}
}