From: <jpg...@us...> - 2007-10-17 00:22:06
|
Revision: 1204 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1204&view=rev Author: jpgrayson Date: 2007-10-16 17:22:10 -0700 (Tue, 16 Oct 2007) Log Message: ----------- Add ability to log stresstest output through a log file. Apply timestamp to stresstest log messages. Modified Paths: -------------- trunk/simpleclient/stresstest/file.c trunk/simpleclient/stresstest/stresstest.c Modified: trunk/simpleclient/stresstest/file.c =================================================================== --- trunk/simpleclient/stresstest/file.c 2007-10-16 23:40:00 UTC (rev 1203) +++ trunk/simpleclient/stresstest/file.c 2007-10-17 00:22:10 UTC (rev 1204) @@ -3,6 +3,12 @@ #include <stdio.h> #include "file.h" +#ifdef __GNUC__ +void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); +#else +void mylog(const char * fmt, ...); +#endif + static struct ogg_stream *audio_stream; static struct ogg_stream *video_stream; @@ -27,7 +33,7 @@ { if ( os->last != NULL ) { - fprintf(stderr, "Queue inconsistency, bailing...\n"); + mylog("Queue inconsistency, bailing...\n"); return; } os->first = node; @@ -37,7 +43,7 @@ { if ( os->last == NULL ) { - fprintf(stderr, "Queue inconsistency, bailing...\n"); + mylog("Queue inconsistency, bailing...\n"); return; } os->last->next = node; @@ -65,7 +71,8 @@ struct theora_headers *th; long timestamp = 0; - //fprintf(stderr, "Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", serialno, op->bytes, op->packetno, op->granulepos); + //mylog("Got theora packet, serialno=%d, size=%d, packetno=%lld, granulepos=%lld\n", + // serialno, op->bytes, op->packetno, op->granulepos); th = (struct theora_headers *)video_stream->data; @@ -118,7 +125,8 @@ audio_stream->page_count++; cnt++; - //fprintf(stderr, "Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", serialno, op->bytes, op->packetno, op->granulepos, timestamp); + //mylog("Got speex packet, serialno=%ld, size=%ld, packetno=%lld, granulepos=%lld, timestamp=%ld\n", + // serialno, op->bytes, op->packetno, op->granulepos, timestamp); // Ignore the first two packets, they are headers if ( cnt > 2 ) @@ -139,7 +147,7 @@ if ( memcmp(op->packet, theoraId, strlen(theoraId)) == 0 ) { - //fprintf(stderr, "Detected a Theora stream with serialno=%d\n", serialno); + //mylog("Detected a Theora stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_theora_cb, NULL); video_stream->serialno = serialno; @@ -152,13 +160,14 @@ read_theora_cb(oggz, op, serialno, data); } else if ( memcmp(op->packet, speexId, strlen(speexId)) == 0 ) { - //fprintf(stderr, "Detected a Speex stream with serialno=%d\n", serialno); + //mylog("Detected a Speex stream with serialno=%d\n", serialno); oggz_set_read_callback(oggz, serialno, read_speex_cb, NULL); audio_stream->serialno = serialno; read_speex_cb(oggz, op, serialno, data); } else { - fprintf(stderr, "Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n", serialno, op->bytes, op->packetno, op->granulepos); + mylog("Got unknown ogg packet, serialno=%d, size=%d, packetno=%d, granulepos=%d\n", + serialno, op->bytes, op->packetno, op->granulepos); } return 0; } @@ -171,7 +180,8 @@ audio_stream->page_count = 0; } else if ( serialno == video_stream->serialno ) { - //fprintf(stderr, "Got theora page serialno=%d, header_len=%d, body_len=%d, granulepos=%lld\n", serialno, og->header_len, og->body_len, ogg_page_granulepos(og)); + //mylog("Got theora page serialno=%d, header_len=%d, body_len=%d, granulepos=%lld\n", + // serialno, og->header_len, og->body_len, ogg_page_granulepos(og)); } return 0; } @@ -183,7 +193,9 @@ node = os->first; while ( node != NULL ) { - fprintf(stderr, "Size=%ld, Stream=%ld, packetno=%lld, timestamp=%ld\n", node->op->bytes, node->serialno, node->op->packetno, node->timestamp); + mylog("Size=%ld, Stream=%ld, packetno=%lld, timestamp=%ld\n", + node->op->bytes, node->serialno, + node->op->packetno, node->timestamp); node = node->next; } } @@ -195,9 +207,9 @@ oggz = oggz_open(filename, OGGZ_READ | OGGZ_AUTO); if ( oggz == NULL ) { - fprintf(stderr, "Error opening ogg file\n"); + mylog("Error opening ogg file\n"); } - fprintf(stderr, "Successfully opened ogg file %s\n", filename); + mylog("Successfully opened ogg file %s\n", filename); // Initialize internal streams audio_stream = calloc(1, sizeof(struct ogg_stream)); @@ -208,9 +220,9 @@ oggz_run(oggz); - //fprintf(stderr, "Audio stream, serialno=%d\n", audio_stream->serialno); + //mylog("Audio stream, serialno=%d\n", audio_stream->serialno); //dump_stream(audio_stream); - //fprintf(stderr, "Video stream, serialno=%d\n", video_stream->serialno); + //mylog("Video stream, serialno=%d\n", video_stream->serialno); //dump_stream(video_stream); oggz_close(oggz); Modified: trunk/simpleclient/stresstest/stresstest.c =================================================================== --- trunk/simpleclient/stresstest/stresstest.c 2007-10-16 23:40:00 UTC (rev 1203) +++ trunk/simpleclient/stresstest/stresstest.c 2007-10-17 00:22:10 UTC (rev 1204) @@ -13,6 +13,7 @@ * the GNU Lesser (Library) General Public License */ +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -62,18 +63,43 @@ static struct timeval start_time; +static FILE * log_file = 0; + +#ifdef __GNUC__ +void mylog(const char * fmt, ...) __attribute__ ((format (printf, 1, 2))); +#endif + +void mylog(const char * fmt, ...) +{ + va_list ap; + time_t t; + struct tm * tmp; + char str[1024]; + char time_str[1024]; + + t = time(0); + tmp = localtime(&t); + + strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", tmp); + snprintf(str, sizeof(str), "stresstest: %s: %s", time_str, fmt); + + va_start(ap, fmt); + vfprintf(log_file ? log_file : stderr, str, ap); + va_end(ap); +} + /* routine used to shutdown and close nicely.*/ void hangup_and_exit(int code) { - fprintf(stderr,"Dump call\n"); + mylog("Dump call\n"); iaxc_dump_call(); - fprintf(stderr,"Sleep for 500 msec\n"); + mylog("Sleep for 500 msec\n"); iaxc_millisleep(500); - fprintf(stderr,"Stop processing thread\n"); + mylog("Stop processing thread\n"); iaxc_stop_processing_thread(); - fprintf(stderr,"Calling iaxc_shutdown..."); + mylog("Calling iaxc_shutdown...\n"); iaxc_shutdown(); - fprintf(stderr,"Exiting with code %d\n", code); + mylog("Exiting with code %d\n", code); exit(code); } @@ -87,12 +113,12 @@ void fatal_error(char *err) { - fprintf(stderr, "FATAL ERROR: %s\n", err); + mylog("FATAL ERROR: %s\n", err); exit(TEST_UNKNOWN_ERROR); } int levels_callback(float input, float output) { - //fprintf(stderr,"Input level: %f\nOutput level: %f\n",input,output); + //mylog("Input level: %f\nOutput level: %f\n", input, output); return 1; } @@ -102,12 +128,12 @@ if ( !print_netstats ) return 0; - if(i++%25 == 0) - fprintf(stderr, "RTT\t" + if ( i++ % 25 == 0 ) + mylog("RTT\t" "Rjit\tRlos%%\tRlosC\tRpkts\tRdel\tRdrop\tRooo\t" "Ljit\tLlos%%\tLlosC\tLpkts\tLdel\tLdrop\tLooo\n"); - fprintf(stderr, "%d\t" + mylog("%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\n", @@ -154,20 +180,21 @@ iaxc_set_video_prefs(prefs); } } else - fprintf(stderr, "Text message received: %s\n", message); + mylog("Text message received: %s\n", message); } void usage() { - printf("Usage is: stresstest <options>\n\n" + printf("Usage: stresstest <options>\n\n" "available options:\n" - " -F <codec,framerate,bitrate,width,height,fragsize> set video parameters\n" + " -F <codec> <framerate> <bitrate> <width> <height> <fragsize> set video parameters\n" " -o <filename> media file to run\n" " -v stop sending video\n" " -a stop sending audio\n" " -l run file in a loop\n" - " -n dump periodic netstats to stderr\n" + " -n dump periodic netstats to log file\n" " -t <timeout> terminate after timeout seconds and report status via return code\n" + " -L <FILE> log to FILE\n" "\n" ); exit(1); @@ -175,16 +202,16 @@ int test_mode_state_callback(struct iaxc_ev_call_state s) { - printf("Call #%d state %d\n", s.callNo, s.state); + mylog("Call #%d state %d\n", s.callNo, s.state); if ( s.state & IAXC_CALL_STATE_COMPLETE ) { - fprintf(stderr, "Call answered\n"); + mylog("Call answered\n"); call_established = 1; } if (s.state == IAXC_CALL_STATE_FREE) { - fprintf(stderr,"Call terminated\n"); + mylog("Call terminated\n"); running = 0; } @@ -273,6 +300,16 @@ usage(); timeout = 1000 * atoi(argv[++i]); break; + case 'L': + if ( i+1 >= argc ) + usage(); + if ( !(log_file = fopen(argv[++i], "w")) ) + { + mylog("failed to open log \"%s\"\n", + argv[i]); + exit(1); + } + break; default: usage(); } @@ -282,15 +319,14 @@ if ( dest == NULL ) { - // We need a destination to call - fprintf(stderr, "No destination, quitting\n"); + mylog("No destination, quitting\n"); return -1; } if ( ogg_file ) load_ogg_file(ogg_file); else - fprintf(stderr, "No media file, running dry\n"); + mylog("No media file, running dry\n"); // Get start time for timeouts gettimeofday(&start_time, NULL); @@ -316,7 +352,7 @@ if (callNo <= 0) iaxc_select_call(callNo); else - fprintf(stderr, "Failed to make call to '%s'", dest); + mylog("Failed to make call to '%s'", dest); // Wait for the call to be established; while ( !call_established ) @@ -362,7 +398,7 @@ running = 0; } - fprintf(stderr, "Received %d audio frames and %d video frames\n", + mylog("Received %d audio frames and %d video frames\n", audio_frames_count, video_frames_count); if ( audio_frames_count == 0 && video_frames_count == 0 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |