summaryrefslogtreecommitdiff
path: root/xc/lib/GL/highpc.c
blob: c9218d02a3221182147099e9ae27ec51cfd1d7b1 (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
#include <stdio.h>
#include <stdlib.h>


/* Mesa shared lib profiling code by Josh Vanderhoof.  Adapted
 * (trivially) to the DRI by Keith Whitwell. 
 */

/*
 * This is the highest address in libGL.so
 */
void glx_highpc(void) { }

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

void monstartup( char *lowpc, char *highpc );
void _mcleanup( void );
void glx_lowpc( void );

static int profile = 0;


/*
 * Start profiling
 */
void __attribute__ ((constructor))
glx_init_prof( void )
{
   FILE *fp;
   char *s = getenv("GLX_SO_MON");

   fprintf(stderr, "\n\n\nIn glx_init_prof\n\n\n");

   if (!s) return;

   profile = 1;
   monstartup( (char *)glx_lowpc, (char *)glx_highpc );

   fprintf(stderr, "Starting profiling, %x %x\n", 
	   (unsigned int)glx_lowpc, 
	   (unsigned int)glx_highpc);

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



/*
 * Finish profiling
 */
void __attribute__ ((destructor))
glx_fini_prof( void )
{
   fprintf(stderr, "in glx_fini_prof\n");

   if (profile) {
      _mcleanup();
      profile = 0;
      fprintf(stderr, "Finished profiling\n");
   }
}




#else

void force_init_prof( void )
{
}

#endif