2 * Copyright (c) 1994 David Mosberger-Tang.
4 * This is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or (at
7 * your option) any later version.
9 * __bb_exit_func() dumps all the basic-block statistics linked into
10 * the bb_head chain to .d files.
17 /* structure emitted by -a */
24 const unsigned long *addresses;
27 struct bb *__bb_head = (struct bb *)0;
33 const int version = GMON_VERSION;
38 * GEN_GMON_CNT_FILE should be defined on systems with mcleanup()
39 * functions that do not write basic-block to gmon.out. In such
40 * cases profiling with "-pg -a" would result in a gmon.out file
41 * without basic-block info (because the file written here would
42 * be overwritten. Thus, a separate file is generated instead.
43 * The two files can easily be combined by specifying them
44 * on gprof's command line (and possibly generating a gmon.sum
45 * file with "gprof -s").
47 #ifndef GEN_GMON_CNT_FILE
48 # define OUT_NAME "gmon.out"
50 # define OUT_NAME "gmon.cnt"
52 fp = fopen(OUT_NAME, "wb");
57 memcpy(&ghdr.cookie[0], GMON_MAGIC, 4);
58 memcpy(&ghdr.version, &version, sizeof(version));
59 fwrite(&ghdr, sizeof(ghdr), 1, fp);
61 for (ptr = __bb_head; ptr != 0; ptr = ptr->next) {
62 u_int ncounts = ptr->ncounts;
66 tag = GMON_TAG_BB_COUNT;
67 fwrite(&tag, sizeof(tag), 1, fp);
68 fwrite(&ncounts, sizeof(ncounts), 1, fp);
70 for (i = 0; i < ncounts; ++i) {
71 fwrite(&ptr->addresses[i], sizeof(ptr->addresses[0]), 1, fp);
72 fwrite(&ptr->counts[i], sizeof(ptr->counts[0]), 1, fp);
76 } /* __bb_exit_func */
78 /*** end of __bb_exit_func.c ***/