Macros | Functions | Variables
sprof.c File Reference
#include <stdio.h>
#include <string.h>
#include <malloc.h>

Go to the source code of this file.

Macros

#define NUM_FILES   200
 

Functions

void add_line (int fn, int l)
 
void add_fn (int fn, char *b)
 
void print_line (int l)
 
int main (int argc, char **argv)
 

Variables

FILE * f
 
char * file_names [NUM_FILES]
 
int * line_buf [NUM_FILES]
 
char buf [200]
 
int fn_cnt =0
 

Macro Definition Documentation

#define NUM_FILES   200

Definition at line 6 of file sprof.c.

Function Documentation

void add_fn ( int  fn,
char *  b 
)

Definition at line 23 of file sprof.c.

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 }
int * line_buf[NUM_FILES]
Definition: sprof.c:9
void * malloc(size_t size)
Definition: omalloc.c:92
#define strdup
Definition: omAllocFunc.c:17
const poly b
Definition: syzextra.cc:213
char * file_names[NUM_FILES]
Definition: sprof.c:8
void add_line ( int  fn,
int  l 
)

Definition at line 13 of file sprof.c.

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 }
int * line_buf[NUM_FILES]
Definition: sprof.c:9
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
int l
Definition: cfEzgcd.cc:94
int main ( int  argc,
char **  argv 
)

Definition at line 73 of file sprof.c.

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 }
void add_fn(int fn, char *b)
Definition: sprof.c:23
int fn_cnt
Definition: sprof.c:11
FILE * f
Definition: sprof.c:5
char buf[200]
Definition: sprof.c:10
void print_line(int l)
Definition: sprof.c:30
#define NUM_FILES
Definition: sprof.c:6
int i
Definition: cfEzgcd.cc:123
void add_line(int fn, int l)
Definition: sprof.c:13
#define NULL
Definition: omList.c:10
char * file_names[NUM_FILES]
Definition: sprof.c:8
void print_line ( int  l)

Definition at line 30 of file sprof.c.

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 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int * line_buf[NUM_FILES]
Definition: sprof.c:9
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
const poly b
Definition: syzextra.cc:213
char * file_names[NUM_FILES]
Definition: sprof.c:8
int l
Definition: cfEzgcd.cc:94

Variable Documentation

char buf[200]

Definition at line 10 of file sprof.c.

FILE* f

Definition at line 5 of file sprof.c.

char* file_names[NUM_FILES]

Definition at line 8 of file sprof.c.

int fn_cnt =0

Definition at line 11 of file sprof.c.

int* line_buf[NUM_FILES]

Definition at line 9 of file sprof.c.