// to compile: $gcc -o bpsPlot bpsPlot.c #include #include #include #include int numSamples = 60; static void sig_alarm(int signo) { /* argument is signal number */ return; } int main(int argc, char* argv[]) { int i; FILE *pf; char cmd[256]; char junk[64]; long totalTxBytes_i, totalTXBytes_i_1; struct itimerval timerval; struct timeval period; int signo; FILE * outData; period.tv_sec=1; period.tv_usec=0; timerval.it_interval=timerval.it_value=period; setitimer(ITIMER_REAL, & timerval, NULL); signal(SIGALRM, sig_alarm); sprintf(cmd, "ifconfig %s | grep \"TX packets\" ", argv[1]); outData = fopen("outData.txt", "w"); for (i=-1; i =0) fprintf(outData, "%i %i\n", i,8*(totalTxBytes_i - totalTXBytes_i_1)); totalTXBytes_i_1 = totalTxBytes_i; } period.tv_sec=0; timerval.it_interval=timerval.it_value=period; setitimer(ITIMER_REAL, & timerval, NULL); //stop timer fflush(outData); close(outData); pf = popen("gnuplot", "w"); fprintf(pf, "plot \"%s\" using 1:2 with lines lt 1\n", "outData.txt"); fprintf(pf, "pause -1 \n"); fflush(pf); sleep(5); fprintf(pf, "\n exit"); fflush(pf); pclose(pf); exit(0); }