📄 dbug_ana.c
字号:
tot_time += time; tot_calls++; break; case 'S': sscanf (buf+2, "%lx %lx %64s", &fn_sbot, &fn_ssz, fn_name); DBUG_PRINT ("srec", ("%lx %lx %s", fn_sbot, fn_ssz, fn_name)); pos = add (fn_name); lastuse = modules[pos].m_stkuse;#if 0 /* * Needs further thought. Stack use is determined by * difference in stack between two functions with DBUG_ENTER * macros. If A calls B calls C, where A and C have the * macros, and B doesn't, then B's stack use will be lumped * in with either A's or C's. If somewhere else A calls * C directly, the stack use will seem to change. Just * take the biggest for now... */ if (lastuse > 0 && lastuse != fn_ssz) { fprintf (stderr, "warning - %s stack use changed (%lx to %lx)\n", fn_name, lastuse, fn_ssz); }#endif if (fn_ssz > lastuse) { modules[pos].m_stkuse = fn_ssz; } if (fn_sbot > highstack) { highstack = fn_sbot; } else if (fn_sbot < lowstack) { lowstack = fn_sbot; } break; default: fprintf (stderr, "unknown record type '%s'\n", buf[0]); break; } next_line:; } /* * Now, we've hit eof. If we still have stuff stacked, then we * assume that the user called exit, so give everything the exited * time of fn_time. */ while (pop (&oldpos,&oldtime,&oldchild)) { time = fn_time - oldtime; t = top (); t -> children += time; time -= oldchild; modules[oldpos].m_time += time; modules[oldpos].m_calls++; tot_time += time; tot_calls++; } DBUG_VOID_RETURN;}/* * out_header () -- print out the header of the report. */void out_header (outf)FILE *outf;{ DBUG_ENTER ("out_header"); if (verbose) { fprintf (outf, "Profile of Execution\n"); fprintf (outf, "Execution times are in milliseconds\n\n"); fprintf (outf, " Calls\t\t\t Time\n"); fprintf (outf, " -----\t\t\t ----\n"); fprintf (outf, "Times\tPercentage\tTime Spent\tPercentage\n"); fprintf (outf, "Called\tof total\tin Function\tof total Importance\tFunction\n"); fprintf (outf, "======\t==========\t===========\t========== ==========\t========\t\n"); } else { fprintf (outf, "%ld bytes of stack used, from %lx down to %lx\n\n", highstack - lowstack, highstack, lowstack); fprintf (outf, " %%time sec #call ms/call %%calls weight stack name\n"); } DBUG_VOID_RETURN;}/* * out_trailer () - writes out the summary line of the report. */void out_trailer (outf,sum_calls,sum_time)FILE *outf;unsigned long int sum_calls, sum_time;{ DBUG_ENTER ("out_trailer"); if (verbose) { fprintf (outf, "======\t==========\t===========\t==========\t========\n"); fprintf (outf, "%6d\t%10.2f\t%11d\t%10.2f\t\t%-15s\n", sum_calls, 100.0, sum_time, 100.0, "Totals"); } DBUG_VOID_RETURN;}/* * out_item () - prints out the output line for a single entry, * and sets the calls and time fields appropriately. */void out_item (outf, m,called,timed)FILE *outf;register struct module_t *m;unsigned long int *called, *timed;{ char *name = m -> name; register unsigned int calls = m -> m_calls; register unsigned long time = m -> m_time; register unsigned long stkuse = m -> m_stkuse; unsigned int import; double per_time = 0.0; double per_calls = 0.0; double ms_per_call, ftime; DBUG_ENTER ("out_item"); if (tot_time > 0) { per_time = (double) (time * 100) / (double) tot_time; } if (tot_calls > 0) { per_calls = (double) (calls * 100) / (double) tot_calls; } import = (unsigned int) (per_time * per_calls); if (verbose) { fprintf (outf, "%6d\t%10.2f\t%11d\t%10.2f %10d\t%-15s\n", calls, per_calls, time, per_time, import, name); } else { ms_per_call = time; ms_per_call /= calls; ftime = time; ftime /= 1000; fprintf (outf, "%8.2f%8.3f%8u%8.3f%8.2f%8u%8u %-s\n", per_time, ftime, calls, ms_per_call, per_calls, import, stkuse, name); } *called = calls; *timed = time; DBUG_VOID_RETURN;}/* * out_body (outf, root,s_calls,s_time) -- Performs an inorder traversal * on the binary search tree (root). Calls out_item to actually print * the item out. */void out_body (outf, root,s_calls,s_time)FILE *outf;register unsigned int root;register unsigned long int *s_calls, *s_time;{ unsigned long int calls, time; DBUG_ENTER ("out_body"); DBUG_PRINT ("out_body", ("%d,%d",*s_calls,*s_time)); if (root == MAXPROCS) { DBUG_PRINT ("out_body", ("%d,%d",*s_calls,*s_time)); } else { while (root != MAXPROCS) { out_body (outf, s_table[root].lchild,s_calls,s_time); out_item (outf, &modules[s_table[root].pos],&calls,&time); DBUG_PRINT ("out_body", ("-- %d -- %d --", calls, time)); *s_calls += calls; *s_time += time; root = s_table[root].rchild; } DBUG_PRINT ("out_body", ("%d,%d", *s_calls, *s_time)); } DBUG_VOID_RETURN;}/* * output () - print out a nice sorted output report on outf. */void output (outf)FILE *outf;{ unsigned long int sum_calls = 0; unsigned long int sum_time = 0; DBUG_ENTER ("output"); if (n_items == 0) { fprintf (outf, "%s: No functions to trace\n", my_name); exit (EX_DATAERR); } out_header (outf); out_body (outf, 0,&sum_calls,&sum_time); out_trailer (outf, sum_calls,sum_time); DBUG_VOID_RETURN;}#define usage() fprintf (DBUG_FILE,"Usage: %s [-v] [prof-file]\n",my_name)extern int optind, getopt _A((int argc, char **argv, char *opts));extern char *optarg;int main (argc, argv, environ)int argc;char *argv[], *environ[];{ register int c; int badflg = 0; FILE *infile; FILE *outfile = {stdout}; DBUG_ENTER ("main"); DBUG_PROCESS (argv[0]); my_name = argv[0]; while ((c = getopt (argc,argv,"#:v")) != EOF) { switch (c) { case '#': /* Debugging Macro enable */ DBUG_PUSH (optarg); break; case 'v': /* Verbose mode */ verbose++; break; default: badflg++; break; } } if (badflg) { usage (); DBUG_RETURN (EX_USAGE); } if (optind < argc) { FILEOPEN (infile, argv[optind], "r"); } else { FILEOPEN (infile, PRO_FILE, "r"); } process (infile); output (outfile); DBUG_RETURN (EX_OK);}#if !unix && !xenix /* If not unix, getopt() is probably not available *//* * From std-unix@ut-sally.UUCP (Moderator, John Quarterman) Sun Nov 3 14:34:15 1985 * Relay-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site gatech.CSNET * Posting-Version: version B 2.10.2 9/18/84; site ut-sally.UUCP * Path: gatech!akgua!mhuxv!mhuxt!mhuxr!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!ut-sally!std-unix * From: std-unix@ut-sally.UUCP (Moderator, John Quarterman) * Newsgroups: mod.std.unix * Subject: public domain AT&T getopt source * Message-ID: <3352@ut-sally.UUCP> * Date: 3 Nov 85 19:34:15 GMT * Date-Received: 4 Nov 85 12:25:09 GMT * Organization: IEEE/P1003 Portable Operating System Environment Committee * Lines: 91 * Approved: jsq@ut-sally.UUCP * * Here's something you've all been waiting for: the AT&T public domain * source for getopt(3). It is the code which was given out at the 1985 * UNIFORUM conference in Dallas. I obtained it by electronic mail * directly from AT&T. The people there assure me that it is indeed * in the public domain. * * There is no manual page. That is because the one they gave out at * UNIFORUM was slightly different from the current System V Release 2 * manual page. The difference apparently involved a note about the * famous rules 5 and 6, recommending using white space between an option * and its first argument, and not grouping options that have arguments. * Getopt itself is currently lenient about both of these things White * space is allowed, but not mandatory, and the last option in a group can * have an argument. That particular version of the man page evidently * has no official existence, and my source at AT&T did not send a copy. * The current SVR2 man page reflects the actual behavor of this getopt. * However, I am not about to post a copy of anything licensed by AT&T. * * I will submit this source to Berkeley as a bug fix. * * I, personally, make no claims or guarantees of any kind about the * following source. I did compile it to get some confidence that * it arrived whole, but beyond that you're on your own. * *//*LINTLIBRARY*/int opterr = 1;int optind = 1;int optopt;char *optarg;static void _ERR(s,c,argv)char *s;int c;char *argv[];{ char errbuf[3]; if (opterr) { errbuf[0] = c; errbuf[1] = '\n'; (void) fprintf(stderr, "%s", argv[0]); (void) fprintf(stderr, "%s", s); (void) fprintf(stderr, "%s", errbuf); }}int getopt(argc, argv, opts)int argc;char **argv, *opts;{ static int sp = 1; register int c; register char *cp; if(sp == 1) if(optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return(EOF); else if(strcmp(argv[optind], "--") == 0) { optind++; return(EOF); } optopt = c = argv[optind][sp]; if(c == ':' || (cp=strchr(opts, c)) == NULL) { _ERR(": illegal option -- ", c, argv); if(argv[optind][++sp] == '\0') { optind++; sp = 1; } return('?'); } if(*++cp == ':') { if(argv[optind][sp+1] != '\0') optarg = &argv[optind++][sp+1]; else if(++optind >= argc) { _ERR(": option requires an argument -- ", c, argv); sp = 1; return('?'); } else optarg = argv[optind++]; sp = 1; } else { if(argv[optind][++sp] == '\0') { sp = 1; optind++; } optarg = NULL; } return(c);}#endif /* !unix && !xenix */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -