liblog-bdm/util/logbench.c

151 lines
3.8 KiB
C
Raw Normal View History

2000-07-31 15:15:35 +02:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <sys/time.h>
#define LOG_MODE 1
#include <log.h>
#include <tool.h>
typedef struct {
double sec;
long count;
struct timeval start;
struct timeval stop;
} cpt;
#define t_init(x) {x.sec = 0; x.count = 0;}
#define t_start(x) {gettimeofday(&(x.start), NULL);}
#define t_stop(x) {gettimeofday(&(x.stop), NULL); x.sec += (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000; x.count++;}
int main (int argc, char ** argv)
{
LOGT_Channel * My_Channel;
char Line [1000], * Event_Data;
FILE * fid;
unsigned int Nb_Send, Line_Number, i;
cpt Compteur;
if (argc != 2)
{
fprintf (stderr, "Usage : %s <event_list>\n", argv [0]);
return -1;
}
/* Ouverture du fichier de test */
fid = fopen (argv [1], "r");
if (!fid)
{
fprintf (stderr, "Unable to open file \"%s\" for reading\n", argv [1]);
return -1;
}
/* Ouverture de la librairie */
if (LOG_Library_Open (0, NULL, LOGD_OPEN | LOGD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible d'ouvrir la librairie LIBLOG\n");
return -1;
}
/* Ouverture d'un channel */
if (LOG_Channel_Open (&My_Channel, 0, 1, "IPR_CAVpopulate2.pc", "IPR_CAV") != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible d'ouvrir un channel\n");
return -1;
}
/* Ajout des tables de routage utilisateur */
if (TL_Channel_RTab_Add (My_Channel, "UTILS:ROOTING:ROOTING_TABLE") != TLS_OK)
{
fprintf (stderr, "\n=> Impossible d'ajouter les tables de routage au channel\n");
LOG_Channel_Close (My_Channel);
return -1;
}
/* Ajout des triggers */
if (TL_Channel_Trigger_Add (My_Channel, "UTILS:ROOTING:TRIGGER") != TLS_OK)
{
fprintf (stderr, "\n=> Impossible d'ajouter les triggers au channel\n");
LOG_Channel_Close (My_Channel);
return -1;
}
/* Initialisation du compteur */
t_init (Compteur);
/* Envoi des <20>v<EFBFBD>nements param<61>tr<74>s dans le fichier */
Line_Number = 1;
while (!feof (fid) && fgets (Line, 1000, fid))
{
/* R<>cup<75>ration des informations dans la ligne du fichier */
Event_Data = strchr (Line, '#');
if (Event_Data == NULL)
{
fprintf (stderr, "Warning ligne n<>%d : format incorrect (caract<63>re '#' manquant)\n", Line_Number);
}
else
{
*Event_Data = (char)0;
Nb_Send = atoi (Line);
if (Nb_Send <= 0)
{
fprintf (stderr, "Warning ligne n<>%d : valeur (%d) incorrecte avant le caracat<61>re '#'\n", Line_Number, Nb_Send);
Nb_Send = 1;
}
Event_Data++;
for (i = 0; i < Nb_Send; i++)
{
t_start (Compteur);
/* Envoi de l'<27>v<EFBFBD>nement proprement dit */
if (LOG_Event_External_Send (My_Channel, argv [1], Event_Data) == LOGD_RC_WARNING)
fprintf (stderr, "Warning ligne n<>%d : code retour WARNING sur envoi de l'<27>v<EFBFBD>nement\n", Line_Number);
t_stop (Compteur);
}
}
Line_Number++;
}
fclose (fid);
/* Affichage du r<>sultat du benchmark */
fprintf (stdout, "%ld <20>v<EFBFBD>nements envoy<6F>s en %.2f sec (%.2f <20>vt/sec)\n", Compteur.count, Compteur.sec, Compteur.count / Compteur.sec);
/* Fermeture du channel */
if (LOG_Channel_Close (My_Channel) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible de fermer le channel\n");
return -1;
}
/* Fermeture de la librairie */
if (LOG_Library_Close (LOGD_CLOSE) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible de fermer la librairie LIBLOG\n");
return -1;
}
return 1;
}