/****************************************************************************************/ /* Copyright (C) 2003 Cesar Delgado */ /* All right reserved */ /* */ /* 1. Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* */ /* 2. Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in the */ /* documentation and/or other materials provided with the distribution. */ /* */ /* 3. The names of its contributors may not be used to endorse or promote */ /* products derived from this software without specific prior written */ /* permission. */ /* */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */ /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, */ /* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */ /* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /* Feedback is welcome. */ /* email: cdelgad2@bigred.unl.edu */ /****************************************************************************************/ #include #include #include //Functions void error_message() ; void gnuplotStart() ; void parser(char *in, FILE *out) ; void gnuplotPlot() ; void quit() ; //Global variables static FILE *pipe1 ; static FILE *pipe2 ; int main(int argc, char* argv[]) { FILE *read, *file ; char string[255] ; char out_file1[] = "/tmp/out1.plot" ; char out_file2[] = "/tmp/out2.plot" ; // signal(SIGINT, quit) ; //catch them signals if (argc == 2) { //Check to see if we are reading from stdin or a file read = fopen(argv[1], "r") ; } else { read = fopen("/dev/stdin", "r") ; } file = fopen(out_file1, "w") ; //Open the file we are goign to write to gnuplotStart() ; //Start Gnuplot with all the feaures we want if (fgets(string, 255, read) == 0) printf("ERROR: File is empty or somethin'\n") ; do { parser(string, file) ; gnuplotPlot() ; // usleep(700000) ; } while (fgets(string, 255, read) != 0) ; fclose(read) ; //Close the input file fclose(file) ; //Close the outpur file pclose(pipe1) ; //Close the pipe return 0 ; } void error_message() { printf("ERROR: Flags?! Flags?! We don't need no stinkin' flags!\n") ; exit(0) ; } void gnuplotStart() { pipe1 = popen("/usr/bin/gnuplot -persist > /dev/null", "w") ; fprintf(pipe1, "%s", "set terminal x11\n set title 'CPU time vs Wall time'\n") ; fflush(pipe1) ; if (pipe1 == NULL) exit(2) ; pipe2 = popen("/usr/bin/gnuplot -persist > /dev/null", "w") ; fprintf(pipe2, "%s", "set terminal x11\n set title 'CPU time per step vs Wall time per step'\n") ; fflush(pipe2) ; if (pipe2 == NULL) exit(2) ; } void parser(char *in, FILE *out) { char timing[20], cpu[20], cpuTime[20], wall[20], wallTime[20], tmp[20] ; char *buf ; sscanf(in, "%s %s %s %s %s %s %s %s", tmp, timing, tmp, cpu, cpuTime, tmp, wall, wallTime) ; buf = strchr(cpu, ',') ; //Get rid of the ',' cpu[buf-cpu] = '\0' ; buf = strchr(cpuTime, '/') ; //Get rid of the lousy text cpuTime[buf-cpuTime] = '\0' ; buf = strchr(wall, ',') ; //That dang ',' again wall[buf-wall] = '\0' ; buf = strchr(wallTime, '/') ; // More lousy text wallTime[buf-wallTime] = '\0' ; fprintf(out, "%s %s %s %s %s \n", timing, cpu, cpuTime, wall, wallTime) ; fflush(out) ; } void gnuplotPlot() { fprintf(pipe1, "%s", "plot '/tmp/out1.plot' using 1:2 title 'CPU' with lines, '/tmp/out1.plot' using 1:4 title 'Wall' with lines\n") ; fflush(pipe1) ; fprintf(pipe2, "%s", "plot '/tmp/out1.plot' using 1:3 title 'CPU per step' with lines, '/tmp/out1.plot' using 1:5 title 'Wall per step' with lines\n") ; fflush(pipe2) ; } void quit() { printf("Exiting\n") ; pclose(pipe1) ; exit(0) ; }