]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - scripts/thread_analysis.c
1 /* Analyzes the concurrent use of charon's threads
3 * Copyright (C) 2008 Andreas Steffen
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 #define LOGFILE "moon.daemon.log"
25 typedef enum state_t state_t
;
36 typedef enum print_t print_t
;
44 static char *state_names
[] = { "idle", "init", "auth", "busy", "retry", "error" };
46 static int readline(FILE *fd
, char *line
)
48 while (fread(line
, 1, 1, fd
))
61 static void printline(state_t
*state
, char *timestamp
)
63 int states
[] = { 0, 0, 0, 0, 0};
67 printf(" <td class=\"log\">%.15s</td>", timestamp
);
69 for (th
= 1; th
<= THREADS
; th
++)
72 printf("<td class=\"%s\"></td>", state_names
[state
[th
]]);
74 total
= states
[STATE_INIT
] + states
[STATE_AUTH
] + states
[STATE_BUSY
] + states
[STATE_RETRY
];
75 printf("<td class=\"init\">%d</td><td class=\"auth\">%d</td><td class=\"busy\">%d</td>",
76 states
[STATE_INIT
], states
[STATE_AUTH
], total
);
77 for (th
= 10; th
<= (THREADS
+ 2); th
+= 5)
79 printf("<td class=\"%s\"></td>", (th
<= total
+ 2)? "busy":"idle");
85 int main(int argc
, char *argv
[])
93 state_t state
[THREADS
+ 1];
95 /* threads 1..5 and 9 are always busy */
96 for (th
= 1; th
<= THREADS
; th
++)
98 state
[th
] = (th
<= 7 && th
!= 3)? STATE_BUSY
: STATE_IDLE
;
101 /* open the log file */
102 fd
= fopen(LOGFILE
, "r");
105 printf("could not open log file '%s'\n", LOGFILE
);
111 printf(" <title>Charon Thread Analysis</title>\n");
112 printf(" <style>\n");
113 printf(" body { font: 11px verdana,arial, helvetica, sans-serif }\n");
114 printf(" td { font: 10px verdana,arial, helvetica, sans-serif;\n");
115 printf(" text-align: center; padding: 0px 1px 0px 1px; background: #FFFF66 }\n");
116 printf(" td.log { text-align: left; background: #FFFF66; white-space: nowrap }\n");
117 printf(" td.idle { background: #FFFF66 }\n");
118 printf(" td.init { background: #FFA522 }\n");
119 printf(" td.auth { background: #90EE90 }\n");
120 printf(" td.busy { background: #ADD8E6 }\n");
121 printf(" td.retry { background: #7B68EE }\n");
122 printf(" td.error { background: #FF6347 }\n");
123 printf(" hr { background-color: #000000; border: 0; height: 1px; }\n");
124 printf(" a:visited { color: #000000 }\n");
125 printf(" a:link { color: #000000 }\n");
126 printf(" a:hover { color: #0000FF }\n");
127 printf(" </style>\n");
130 printf(" <h1>Charon Thread Analysis</h1>\n");
131 printf(" <table>\n");
133 /* print table header */
135 printf(" <td class=\"log\">Timestamp</td>");
136 for (th
= 1 ; th
<= THREADS
; th
++)
138 printf("<td>%02d</td>", th
);
140 printf("<td class=\"init\">I</td><td class=\"auth\">A</td><td class=\"busy\">B</td>");
141 for (th
= 10; th
<= (THREADS
+ 2); th
+= 5)
143 printf("<td class=\"busy\">%d</td>", (th
== 100)? 99:th
);
148 while (readline(fd
, line
))
150 char *p_section
, *p_charon
, *p_thread
, *p_log
;
152 p_section
= strstr(line
, "---");
155 printline(state
, line
);
168 p_charon
= strstr(line
, "charon");
174 /* determine thread */
175 p_thread
= p_charon
+ 8;
178 /* determine log message */
179 p_log
= p_charon
+ 16;
180 if (strstr(p_log
, "received packet"))
182 if (mode
== MODE_DEL
)
184 printline(state
, line
);
187 if (state
[th
] != STATE_IDLE
)
189 state
[th
] = STATE_ERROR
;
193 state
[th
] = STATE_BUSY
;
196 if (strstr(p_log
, "sending packet"))
198 if (mode
== MODE_ADD
)
200 printline(state
, line
);
203 if (state
[th
] == STATE_IDLE
)
205 state
[th
] = STATE_ERROR
;
209 state
[th
] = STATE_IDLE
;
212 if (strstr(p_log
, "parsed IKE_SA_INIT request"))
214 if (state
[th
] != STATE_BUSY
)
216 state
[th
] = STATE_ERROR
;
220 state
[th
] = STATE_INIT
;
223 if (strstr(p_log
, "parsed IKE_AUTH request"))
225 if (state
[th
] != STATE_BUSY
)
227 state
[th
] = STATE_ERROR
;
231 state
[th
] = STATE_AUTH
;
234 if (strstr(p_log
, "already processing"))
236 if (state
[th
] != STATE_IDLE
)
238 state
[th
] = STATE_ERROR
;
242 state
[th
] = STATE_RETRY
;
244 printline(state
, line
);
246 state
[th
] = STATE_IDLE
;
249 printf(" </table>\n");
251 printf(" <table>\n");
253 printf(" <td class=\"init\"> I </td><td>IKE_SA_INIT Thread </td>\n");
254 printf(" <td class=\"auth\"> A </td><td>IKE_AUTH Thread </td>\n");
255 printf(" <td class=\"retry\"> R </td><td>Retransmit Thread </td>\n");
256 printf(" <td class=\"busy\"> B </td><td>Busy Thread </td>\n");
257 printf(" <td class=\"error\"> E </td><td>State Error </td>\n");
259 printf(" </table>\n");
262 printf(" <em>© 2008\n");
263 printf(" <a href=\"http://ita.hsr.ch?&L=1\" target=\"popup\">\n");
264 printf(" ITA Institute for Internet Technologies and Applications</a> -\n");
265 printf(" <a href=\"http://www.hsr.ch/?&L=1\" target=\"popup\">\n");
266 printf(" HSR Hochschule für Technik Rapperswil</a>\n");