|
转换工具源代码如下: /*********************************************************** Program name : cvemv.c Written by : Zhang Li Min Date : 2003.1.26 Function : Convert output of statements event monitorThe result can be loaded into a table and for analysis ************************************************************/ #define KEYNUMBER 23 #include <stdio.h> #include <string.h>
int SearchText(char *str);
int main(int argc, char ** argv) { FILE *fp_in,*fp_out; char buffer[32767]; char *ptr ="abc" ; int i; int sequence=0; char *oper="sadf"; char *value="skdf"; char rec[KEYNUMBER][32767]; if(argc !=3) { printf("Usage:cvevm input output\n"); exit(1); } fp_in = fopen(argv[1],"r"); fp_out = fopen(argv[2],"w"); if((fp_in == NULL) || (fp_out == NULL)) { printf("open file failure\n"); exit(1); } while(!feof(fp_in)) { fgets(buffer,sizeof(buffer),fp_in); if(feof(fp_in)) break; ptr = strstr(buffer,"Statement Event"); if(ptr) { sequence++; while(1) { fgets(buffer,sizeof(buffer),fp_in); if(feof(fp_in)) break; if (!strncmp(buffer," sqlstate",11)) { break; } oper = strtok(buffer,":"); if(oper) { i = SearchText(oper); if(i > 0){ value = strtok(NULL,":"); if(value) { value[strlen(value)-1] = 0; strcpy(rec[i],value); } } } } fprintf(fp_out,"%d",sequence); for (i=0;i<KEYNUMBER;i++) { if(i == 10) { rec[i][11] = 0; } if(i == 12) { rec[i][12] = 0; } if(i == 13) { rec[i][10] = 0; } if (i == 9) { fputc('"',fp_out); fprintf(fp_out,"%s",rec[i]); fputc('"',fp_out); fputc(',',fp_out); } else { fprintf(fp_out,"%s,",rec[i]); } }
fprintf(fp_out,"\n"); } } fclose(fp_in); fclose(fp_out); }
int SearchText(char *str) { char *opers[KEYNUMBER] = { " Appl Handle", " Type", " Operation", " Section", " Creator", " Package", " Cursor ", " Cursor was blocking", " Text", " Exec Time", " Number of Agents created", " User CPU", " System CPU", " Fetch Count", " Sorts", " Total sort time", " Sort overflows", " Rows read", " Rows written", " Internal rows deleted", " Internal rows updated", " Internal rows inserted", " sqlcode"}; int i; for(i=0;i<KEYNUMBER;i++) { if (strncmp(str,opers[i],strlen(str)) == 0) { return (i+1); } } return 0; } 请选用C编译器将它编译成执行文件。 用法如下: cvevm inputfile outputfile inputfile 是语句监测器的输出结果,outputfile是处理过后的文件名
|