/* Analyzes the concurrent use of charon's threads * * Copyright (C) 2008 Andreas Steffen * HSR Hochschule fuer Technik Rapperswil * * This program 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 2 of the License, or (at your * option) any later version. See . * * This program 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. */ #include #include #include #define LOGFILE "moon.daemon.log" #define LINE_LEN 2048 #define THREADS 99 typedef enum state_t state_t; enum state_t { STATE_IDLE = 0, STATE_INIT = 1, STATE_AUTH = 2, STATE_BUSY = 3, STATE_RETRY = 4, STATE_ERROR = 5 }; typedef enum print_t print_t; enum print_t { MODE_ANY = 0, MODE_ADD = 1, MODE_DEL = 2 }; static char *state_names[] = { "idle", "init", "auth", "busy", "retry", "error" }; static int readline(FILE *fd, char *line) { while (fread(line, 1, 1, fd)) { if (*line == '\n') { *line = '\0'; return 1; } line++; } *line = '\0'; return 0; } static void printline(state_t *state, char *timestamp) { int states[] = { 0, 0, 0, 0, 0}; int th, total ; printf(" \n"); printf(" %.15s", timestamp); for (th = 1; th <= THREADS; th++) { states[state[th]]++; printf("", state_names[state[th]]); } total = states[STATE_INIT] + states[STATE_AUTH] + states[STATE_BUSY] + states[STATE_RETRY]; printf("%d%d%d", states[STATE_INIT], states[STATE_AUTH], total); for (th = 10; th <= (THREADS + 2); th += 5) { printf("", (th <= total + 2)? "busy":"idle"); } printf("\n"); printf(" \n"); } int main(int argc, char *argv[]) { char line[LINE_LEN]; int section = 0; int mode = MODE_ANY; int th; FILE *fd; state_t state[THREADS + 1]; /* threads 1..5 and 9 are always busy */ for (th = 1; th <= THREADS; th++) { state[th] = (th <= 7 && th != 3)? STATE_BUSY : STATE_IDLE; } /* open the log file */ fd = fopen(LOGFILE, "r"); if (!fd) { printf("could not open log file '%s'\n", LOGFILE); return 1; } printf("\n"); printf("\n"); printf(" Charon Thread Analysis\n"); printf(" \n"); printf("\n"); printf("\n"); printf("

Charon Thread Analysis

\n"); printf(" \n"); /* print table header */ printf(" \n"); printf(" "); for (th = 1 ; th <= THREADS; th++) { printf("", th); } printf(""); for (th = 10; th <= (THREADS + 2); th += 5) { printf("", (th == 100)? 99:th); } printf("\n"); printf(" \n"); while (readline(fd, line)) { char *p_section, *p_charon, *p_thread, *p_log; p_section = strstr(line, "---"); if (p_section) { printline(state, line); mode = MODE_ANY; if (section++ < 1) { continue; } else { break; } } p_charon = strstr(line, "charon"); if (!p_charon) { continue; } /* determine thread */ p_thread = p_charon + 8; th = atol(p_thread); /* determine log message */ p_log = p_charon + 16; if (strstr(p_log, "received packet")) { if (mode == MODE_DEL) { printline(state, line); } mode = MODE_ADD; if (state[th] != STATE_IDLE) { state[th] = STATE_ERROR; } else { state[th] = STATE_BUSY; } } if (strstr(p_log, "sending packet")) { if (mode == MODE_ADD) { printline(state, line); } mode = MODE_DEL; if (state[th] == STATE_IDLE) { state[th] = STATE_ERROR; } else { state[th] = STATE_IDLE; } } if (strstr(p_log, "parsed IKE_SA_INIT request")) { if (state[th] != STATE_BUSY) { state[th] = STATE_ERROR; } else { state[th] = STATE_INIT; } } if (strstr(p_log, "parsed IKE_AUTH request")) { if (state[th] != STATE_BUSY) { state[th] = STATE_ERROR; } else { state[th] = STATE_AUTH; } } if (strstr(p_log, "already processing")) { if (state[th] != STATE_IDLE) { state[th] = STATE_ERROR; } else { state[th] = STATE_RETRY; } printline(state, line); mode = MODE_ANY; state[th] = STATE_IDLE; } } printf("
Timestamp%02dIAB%d
\n"); printf("

\n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf("
 I IKE_SA_INIT Thread   A IKE_AUTH Thread   R Retransmit Thread   B Busy Thread   E State Error  
\n"); printf("

\n"); printf("


\n"); printf(" © 2008\n"); printf(" \n"); printf(" HSR Hochschule für Technik Rapperswil\n"); printf(" \n"); printf("\n"); printf("\n"); fclose(fd); return 0; }