2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* profile.c -- routines to deal with profiling. 2 June 1986 */
12 #include <afsconfig.h>
13 #include <afs/param.h>
21 #if defined(sun) || defined(mac2)
22 #define PROFSTART 0x8000
28 #define PROFSTART 2 /* Verify This! */
31 #define PROFSTART 0x2000
36 #define SCALE_1_TO_1 0x10000L
39 extern void *malloc();
41 extern char *malloc();
46 static char *profBuf = NULL;
47 static int profBufSize;
48 static int profSig = -1;
49 static int profiling = 0;
58 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
59 /* Soon should handle aix profiling */
61 memset(profBuf, 0, profBufSize);
62 /* the following code is to replace the monitor call below */
63 /* monitor (PROFSTART, &etext, profBuf, profBufSize, 0); */
64 profileHeader.startpc = PROFSTART;
65 profileHeader.endpc = (afs_int32)&etext;
66 profileHeader.count = 0;
67 profil(profBuf, profBufSize, PROFSTART, SCALE_1_TO_1);
75 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
76 /* Soon should handle aix profiling */
82 f = open("mon.out", O_CREAT|O_TRUNC|O_WRONLY, 0666);
85 write(f, &profileHeader, sizeof(profileHeader));
86 write(f, profBuf, profBufSize);
91 /* Allocate the profiling buffer */
94 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
95 /* Soon should handle aix profiling */
98 profBufSize = (int) &etext - PROFSTART;
99 profBuf = (char *)malloc (profBufSize);
100 if (profBuf == NULL) {
101 fprintf (stderr, "Couldn't get profiling buffer.\n");
108 /* Arrange to start and stop profiling when signo is sent. */
109 void ProfileSig(int signo)
111 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
112 /* Soon should handle aix profiling */
116 signal(signo, ProfileToggle);
119 signal(profSig, SIG_DFL);
123 /* Toggle profiling. Can be called as a signal handler. */
126 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
127 /* Soon should handle aix profiling */
128 static char *onMsg = "Profiling turned on.\n";
129 static char *offMsg = "Profiling turned off; mon.out written.\n";
133 write(fileno(stdout), offMsg, strlen(offMsg));
137 write(fileno(stdout), onMsg, strlen(onMsg));