My Project
Loading...
Searching...
No Matches
sprof.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <string.h>
3#include <malloc.h>
4
5VAR FILE *f;
6#define NUM_FILES 200
7
10VAR char buf[200];
11VAR int fn_cnt=0;
12
13void add_line(int fn,int l)
14{
15 if ((l<32000)||(l<0))
16 {
17 int i=l/32;
18 int j=l%32;
19 line_buf[fn][i] |= (1<<j);
20 }
21 else printf("overflow: %d\n",l);
22}
23void add_fn(int fn,char *b)
24{
25 file_names[fn]=strdup(b);
26 line_buf[fn]=(int*)malloc(1000*sizeof(int));
27 memset(line_buf[fn],0,1000*sizeof(int));
28}
29
30void print_line(int l)
31{
32 FILE *fi=fopen(file_names[l],"r");
33 FILE *fo;
34 int i;
35 int ln;
36 if (fi==NULL)
37 {
38 printf("%s not found\n",file_names[l]);
39 return;
40 }
41 else
42 {
43 char b[200];
44 sprintf(b,"%s.prof",file_names[l]);
45 fo=fopen(b,"w");
46 }
47 ln=0;
48 while(!feof(fi))
49 {
50 char line[500];
51 char *s;
52 s=fgets(line,500,fi);ln++;
53 if (s==NULL) break;
54 if((line_buf[l][ln/32] & (1<<(ln %32))))
55 fprintf(fo,"%4d + %s",ln,line);
56 else
57 fprintf(fo,"%4d %s",ln,line);
58 }
59 fclose(fi);
60 fclose(fo);
61 for(i=0;i<1000;i++)
62 {
63 if (line_buf[l][i]!=0)
64 {
65 int j;
66 for(j=0;j<32;j++)
67 if ((1<<j) & line_buf[l][i]) printf("%d,",i*32+j);
68 }
69 }
70 printf("\n");
71}
72
73int main(int argc, char** argv)
74{
75 memset(file_names,0,NUM_FILES*sizeof(char*));
76 f=fopen("smon.out","r");
77 if(f==NULL) { printf("cannot read smon.out\n"); return 2; }
78 while(!feof(f))
79 {
80 if (fgets(buf,200,f)==NULL) break;
81 if ((strncmp(buf,"STDIN",5)!=0)
82 && (strncmp(buf,"(none)",6)!=0)
83 && (strncmp(buf,"::",2)!=0))
84 {
85 /* get fn */
86 int i=0;
87 char c;
88 int line_no;
89 while((buf[i]!=':')&&(i<200)) i++;
90 buf[i]='\0';
91 if (i>=200) continue;
92 while ((buf[i]!=' ')&&(i<200)) i++;
93 sscanf(buf+i,"%d",&line_no);
94 for(i=0;i<fn_cnt;i++)
95 {
96 if (strcmp(file_names[i],buf)==0) { add_line(i,line_no); break; }
97 }
98 if ((i==fn_cnt)&&(i<NUM_FILES))
99 {
100 printf("new file:%s\n",buf);
101 add_fn(i,buf);
102 add_line(i,line_no);
103 fn_cnt++;
104 }
105 }
106 }
107 fclose(f);
108 printf("----- all read\n");
109 {
110 int i;
111 for(i=0;i<fn_cnt;i++)
112 {
113 printf("File %s =============================\n",file_names[i]);
114 print_line(i);
115 }
116 }
117 return(0);
118}
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
CanonicalForm b
Definition: cfModGcd.cc:4103
const CanonicalForm int s
Definition: facAbsFact.cc:51
int j
Definition: facHensel.cc:110
#define VAR
Definition: globaldefs.h:5
#define strdup
Definition: omAllocFunc.c:18
#define malloc
Definition: omAllocFunc.c:12
#define NULL
Definition: omList.c:12
int main()
VAR char buf[200]
Definition: sprof.c:10
void add_line(int fn, int l)
Definition: sprof.c:13
VAR int * line_buf[NUM_FILES]
Definition: sprof.c:9
void print_line(int l)
Definition: sprof.c:30
void add_fn(int fn, char *b)
Definition: sprof.c:23
#define NUM_FILES
Definition: sprof.c:6
VAR FILE * f
Definition: sprof.c:5
VAR int fn_cnt
Definition: sprof.c:11
VAR char * file_names[NUM_FILES]
Definition: sprof.c:8