summaryrefslogtreecommitdiff
path: root/xc/extras/Mesa/src/highpc.c
blob: d35a5ae617940d90c586c79fa399d1f83ab0077c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

/*
 * Mesa 3-D graphics library
 * Version:  3.5
 *
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#ifdef PC_HEADER
#include "all.h"
#else
#include "glheader.h"
#include "mtypes.h"
#endif


/*
 * This is the highest address in Mesa
 */
extern void mesa_highpc(void);  /* silence compiler warning */
void mesa_highpc(void) { }

#if defined(__GNUC__) && defined(__linux__)

void monstartup( char *lowpc, char *highpc );
void _mcleanup( void );
void mesa_lowpc( void );
void mesa_highpc( void );

static int profile = 0;

extern void force_init_prof( void ); /* silence compiler warning */
void force_init_prof( void )
{
   FILE *fp;

   if (profile) return;

   profile = 1;

   monstartup( (char *)mesa_lowpc, (char *)mesa_highpc );

   fprintf(stderr, "Starting profiling, %x %x\n",
	   (unsigned int)mesa_lowpc,
	   (unsigned int)mesa_highpc);

   if ((fp = fopen( "mesa_lowpc", "w" )) != NULL) {
      fprintf( fp, "0x%08x ", (unsigned int)mesa_lowpc );
      fclose( fp );
   }
}

/*
 * Start profiling
 */
extern void init_prof(void); /* silence compiler warning */
void __attribute__ ((constructor))
init_prof( void )
{
   FILE *fp;
   char *s = getenv("MESA_MON");

   if (s == NULL || atoi(s) == 0)
      return;

   profile = 1;

   monstartup( (char *)mesa_lowpc, (char *)mesa_highpc );

      fprintf(stderr, "Starting profiling, %x %x\n",
	      (unsigned int)mesa_lowpc,
	      (unsigned int)mesa_highpc);

   if ((fp = fopen( "mesa_lowpc", "w" )) != NULL) {
      fprintf( fp, "0x%08x ", (unsigned int)mesa_lowpc );
      fclose( fp );
   }
}



/*
 * Finish profiling
 */
extern void fini_prof(void);  /* silence compiler warning */
void __attribute__ ((destructor))
fini_prof( void )
{
   if (profile) {
      _mcleanup( );

	 fprintf(stderr, "Finished profiling\n");
   }
}

#else

void force_init_prof( void )
{
}

#endif