/**************************************************************************** ** tau_reduce.cpp ** Version 1.0 ** Nick Trebon ** 7/2002 **************************************************************************** ** tau_reduce will read in a pprof created dump file and store the ** information. tau_reduce will then generate a exclude list ** that can be used to exclude certain functions when pprof is again ** implemented. ***************************************************************************/ #include "pprof_elem.h" #define SIZE_OF_FILENAME 1024 // Include full path. #ifdef TAU_HP_GNU #define SIZE_OF_LINE 2*1024 // Big line to accomodate long function names #else #define SIZE_OF_LINE 64*1024 // Big line to accomodate long function names #endif FILE* fp; char line[SIZE_OF_LINE]; //input line of file char rule[SIZE_OF_LINE]; //to store a full rule string dumpfilename; //filename of dump file string rulefilename; //filename of rule file string outputfilename; //filename of outputfile int number_of_functions; //number of functions int hwcounters = 0; //are hardware counters used? default 0 int profilestats = 0; //are profile stats used? default 0 (standard deviation) int excl=0; //is element exlusive? default 0 int number_excluded; //number of functions excluded int apply_default_rules=1; //should we apply default rules? default 1 int numstmts; //number of statements in a single rule int verbose=0; //verbose mode? default 0 int output=0; //do we output to a file? default 0 int groupnames_used=0; //groupnames used? default 0; int command_groupname=0; //is this a command with a groupname? default 0; pprof_elem** elemArray; //array that holds the pprof_elem objects string** excludedFunctions; //to hold the function names that will be excluded int** countExcluded; //array to hold number of times a function is excluded //putLine() takes a line and writes it out to the file that is currently opened. //It prints out an error message and exits if an output error occurs. void putLine(string s){ if(fprintf(fp,"%s\n",s.c_str())<0){ perror("Error: fprintf reports an error\n"); exit(0); }//if }//putLine() //getLine() simply reads in a line from the file that is currently opened and stores //it in the line variable. It prints out an error message and exits if an input error //occurs. void getLine(){ if(fgets(line, sizeof(line),fp)==NULL){ perror("Error: fgets returns NULL\n"); exit(0); }//if }//getLine(); //getFunctionName() finds the name of the function that is enclosed in quotation marks //in the line. It then sets the line buffer so it holds the substring that follows //the closing quotation mark. Some names have spaces attached to the end, and others do //not. Determine if there are any extra spaces, and remove them. string getFunctionName(){ string rest = line; rest = rest.substr(rest.find("\"")+1); string s = rest.substr(0,rest.find("\"")); //now, set rest to the remainder of the string after the last quote. Copy to //the line buffer. rest = rest.substr(s.length()+1); strncpy(line, rest.c_str(), rest.length()+1); line[rest.length()]='\0'; //s now equals the string enclosed between the two quotes. Now, remove any //extraneous spaces that may be attached at the end of s. Then, return s. int i=s.rfind(" ",0); while(i==s.length()){ s=s.substr(0,s.length()-1); i=s.rfind(" ",0); }//while return s; }//getFunctionName() //getGroupNamesFromLine() finds the GROUP="g1 | g2 ..." string in the line //and will return a string containing only the names of the groups. string getGroupNamesFromLine(){ string gnames = line; gnames=gnames.substr(gnames.find("\"")+1); gnames=gnames.substr(0,gnames.find("\"")); //now string l is the string contained between the starting and ending //quotation marks. return gnames; }//getGroupNamesFromLine() //select()prints out the output that can be used to implement a select file. //Currently it prints it out to the screen. void select(){ //if we are sending the output to a file, first open and write header. //then, cycle through array of function names and print out one per line. //write header, and close file. if(output){ if((fp=fopen(outputfilename.c_str(), "w"))==NULL){ string errormessage="Error: Could not open outputfile: "; errormessage+=outputfilename+"\n"; perror(errormessage.c_str()); exit(0); }//if putLine("# Selective instrumentation: Specify an exclude/include list.\n\n"); putLine("BEGIN_EXCLUDE_LIST\n"); for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i'){ for(int i=0; i number) (*countExcluded[i])++; }//for }//else if else if(op=='='){ for(int i=0; i