Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

profio.c File Reference

#include "c.h"

Include dependency graph for profio.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  count
struct  file
struct  file::func
struct  file::func::caller

Defines

#define MAXTOKEN   64

Functions

void acaller (char *caller, char *file, int x, int y, int count, struct func *callee)
funcafunction (char *name, char *file, int x, int y, int count)
void apoint (int i, char *file, int x, int y, int count)
int compare (struct count *a, struct count *b)
int findcount (char *file, int x, int y)
filefindfile (char *name)
int findfunc (char *name, char *file)
int gather (void)
int getd (void)
char * getstr (void)
int process (char *file)

Variables

filefilelist
FILEfp


Define Documentation

#define MAXTOKEN   64
 

Definition at line 22 of file profio.c.


Function Documentation

void acaller char *  caller,
char *  file,
int  x,
int  y,
int  count,
struct func callee
[static]
 

Definition at line 46 of file profio.c.

References assert, func::callers, count::count, file, func::link, NEW, PERM, q, r, strcmp(), count::x, x, count::y, and y.

Referenced by gather().

00046                                                                                             {
00047     struct caller *q;
00048 
00049     assert(callee);
00050     for (q = callee->callers; q && (caller != q->name
00051         || file != q->file || x != q->x || y != q->y); q = q->link)
00052         ;
00053     if (!q) {
00054         struct caller **r;
00055         NEW(q, PERM);
00056         q->name = caller;
00057         q->file = file;
00058         q->x = x;
00059         q->y = y;
00060         q->count = 0;
00061         for (r = &callee->callers; *r && (strcmp(q->name, (*r)->name) > 0
00062             || strcmp(q->file, (*r)->file) > 0 || q->y > (*r)->y || q->y > (*r)->y); r = &(*r)->link)
00063             ;
00064         q->link = *r;
00065         *r = q;
00066     }
00067     q->count += count;
00068 }

Here is the call graph for this function:

struct func* afunction char *  name,
char *  file,
int  x,
int  y,
int  count
[static]
 

Definition at line 88 of file profio.c.

References assert, func::callers, compare(), file, findfile(), file::funcs, func::link, func::name, name, NEW, p, PERM, q, and r.

Referenced by gather().

00088                                                                                {
00089     struct file *p = findfile(file);
00090     struct func *q;
00091 
00092     assert(p);
00093     for (q = p->funcs; q && name != q->name; q = q->link)
00094         ;
00095     if (!q) {
00096         struct func **r;
00097         NEW(q, PERM);
00098         q->name = name;
00099         q->count.x = x;
00100         q->count.y = y;
00101         q->count.count = 0;
00102         q->callers = 0;
00103         for (r = &p->funcs; *r && compare(&q->count, &(*r)->count) > 0; r = &(*r)->link)
00104             ;
00105         q->link = *r;
00106         *r = q;
00107     }
00108     q->count.count += count;
00109     return q;
00110 }

Here is the call graph for this function:

void apoint int  i,
char *  file,
int  x,
int  y,
int  count
[static]
 

Definition at line 113 of file profio.c.

References assert, count::count, file::count, count, file::counts, file, findfile(), i, j, newarray, p, PERM, file::size, count::x, count::y, and z.

Referenced by gather().

00113                                                                {
00114     struct file *p = findfile(file);
00115 
00116     assert(p);
00117     if (i >= p->size) {
00118         int j;
00119         if (p->size == 0) {
00120             p->size = i >= 200 ? 2*i : 200;
00121             p->counts = newarray(p->size, sizeof *p->counts, PERM);
00122         } else {
00123             struct count *new;
00124             p->size = 2*i;
00125             new = newarray(p->size, sizeof *new, PERM);
00126             for (j = 0; j < p->count; j++)
00127                 new[j] = p->counts[j];
00128             p->counts = new;
00129         }
00130         for (j = p->count; j < p->size; j++) {
00131             static struct count z;
00132             p->counts[j] = z;
00133         }
00134     }
00135     p->counts[i].x = x;
00136     p->counts[i].y = y;
00137     p->counts[i].count += count;
00138     if (i >= p->count)
00139         p->count = i + 1;
00140 }

Here is the call graph for this function:

int compare struct count a,
struct count b
[static]
 

Definition at line 71 of file profio.c.

References a, b, count::x, and count::y.

Referenced by afunction(), and process().

00071                                                      {
00072     if (a->y == b->y)
00073         return a->x - b->x;
00074     return a->y - b->y;
00075 }

int findcount char *  file,
int  x,
int  y
 

Definition at line 143 of file profio.c.

References c, count::count, file::count, file::counts, file, findfile(), k, l, file::name, count::x, y, and count::y.

Referenced by definept().

00143                                         {
00144     static struct file *cursor;
00145 
00146     if (cursor == 0 || cursor->name != file)
00147         cursor = findfile(file);
00148     if (cursor) {
00149         int l, u;
00150         struct count *c = cursor->counts;
00151         for (l = 0, u = cursor->count - 1; l <= u; ) {
00152             int k = (l + u)/2;
00153             if (c[k].y > y || c[k].y == y && c[k].x > x)
00154                 u = k - 1;
00155             else if (c[k].y < y || c[k].y == y && c[k].x < x)
00156                 l = k + 1;
00157             else
00158                 return c[k].count;
00159         }
00160     }
00161     return -1;
00162 }

Here is the call graph for this function:

struct file* findfile char *  name  )  [static]
 

Definition at line 78 of file profio.c.

References file::link, file::name, and p.

Referenced by afunction(), apoint(), findcount(), findfunc(), gather(), and main().

00078                                          {
00079     struct file *p;
00080 
00081     for (p = filelist; p; p = p->link)
00082         if (p->name == name)
00083             return p;
00084     return 0;
00085 }

int findfunc char *  name,
char *  file
 

Definition at line 165 of file profio.c.

References file, findfile(), file::funcs, func::link, func::name, file::name, and p.

Referenced by funcdefn().

00165                                      {
00166     static struct file *cursor;
00167 
00168     if (cursor == 0 || cursor->name != file)
00169         cursor = findfile(file);
00170     if (cursor) {
00171         struct func *p;
00172         for (p = cursor->funcs; p; p = p->link)
00173             if (p->name == name)
00174                 return p->count.count;
00175     }
00176     return -1;
00177 }

Here is the call graph for this function:

int gather void   )  [static]
 

Definition at line 207 of file profio.c.

References acaller(), afunction(), apoint(), assert, count, f, file, filelist, findfile(), getd(), getstr(), i, func::link, name, func::name, NELEMS, NEW, npoints, PERM, q, x, and y.

00207                         {
00208     int i, nfiles, nfuncs, npoints;
00209     char *files[64];
00210 
00211     if ((nfiles = getd()) < 0)
00212         return 0;
00213     assert(nfiles < NELEMS(files));
00214     for (i = 0; i < nfiles; i++) {
00215         if ((files[i] = getstr()) == 0)
00216             return -1;
00217         if (!findfile(files[i])) {
00218             struct file *new;
00219             NEW(new, PERM);
00220             new->name = files[i];
00221             new->size = new->count = 0;
00222             new->counts = 0;
00223             new->funcs = 0;
00224             new->link = filelist;
00225             filelist = new;
00226         }
00227     }
00228     if ((nfuncs = getd()) < 0)
00229         return -1;
00230     for (i = 0; i < nfuncs; i++) {
00231         struct func *q;
00232         char *name, *file;
00233         int f, x, y, count;
00234         if ((name = getstr()) == 0 || (f = getd()) <= 0
00235         || (x = getd()) < 0 || (y = getd()) < 0 || (count = getd()) < 0)
00236             return -1;
00237         q = afunction(name, files[f-1], x, y, count);
00238         if ((name = getstr()) == 0 || (file = getstr()) == 0
00239         || (x = getd()) < 0 || (y = getd()) < 0)
00240             return -1;
00241         if (*name != '?')
00242             acaller(name, file, x, y, count, q);
00243     }
00244     if ((npoints = getd()) < 0)
00245         return -1;
00246     for (i = 0; i < npoints; i++) {
00247         int f, x, y, count;
00248         if ((f = getd()) < 0 || (x = getd()) < 0 || (y = getd()) < 0
00249         || (count = getd()) < 0)
00250             return -1;
00251         if (f)
00252             apoint(i, files[f-1], x, y, count);
00253     }
00254     return 1;
00255 }

Here is the call graph for this function:

int getd void   )  [static]
 

Definition at line 180 of file profio.c.

References c, EOF, fp, getc, and n.

00180                       {
00181     int c, n = 0;
00182 
00183     while ((c = getc(fp)) != EOF && (c == ' ' || c == '\n' || c == '\t'))
00184         ;
00185     if (c >= '0' && c <= '9') {
00186         do
00187             n = 10*n + (c - '0');
00188         while ((c = getc(fp)) >= '0' && c <= '9');
00189         return n;
00190     }
00191     return -1;
00192 }

char* getstr void   )  [static]
 

Definition at line 195 of file profio.c.

References c, EOF, fp, getc, s, and string().

00195                           {
00196     int c;
00197     char buf[MAXTOKEN], *s = buf;
00198 
00199     while ((c = getc(fp)) != EOF && c != ' ' && c != '\n' && c != '\t')
00200         if (s - buf < (int)sizeof buf - 2)
00201             *s++ = c;
00202     *s = 0;
00203     return s == buf ? (char *)0 : string(buf);
00204 }

Here is the call graph for this function:

int process char *  file  ) 
 

Definition at line 258 of file profio.c.

References compare(), file::count, file::counts, fclose(), file, fopen(), fp, gather(), int, file::link, p, and qsort().

Referenced by main(), and prof_init().

00258                         {
00259     int more;
00260 
00261     if ((fp = fopen(file, "r")) != NULL) {
00262         struct file *p;
00263         while ((more = gather()) > 0)
00264             ;
00265         fclose(fp);
00266         if (more < 0)
00267             return more;
00268         for (p = filelist; p; p = p->link)
00269             qsort(p->counts, p->count, sizeof *p->counts,
00270                 (int (*)(const void *, const void *))
00271                 compare);
00272         
00273         return 1;
00274     }
00275     return 0;
00276 }

Here is the call graph for this function:


Variable Documentation

struct file * filelist
 

FILE* fp
 

Definition at line 43 of file profio.c.


Generated on Thu Aug 25 15:55:22 2005 for Quake III Arena by  doxygen 1.3.9.1