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>
20 #if defined(sun) || defined(mac2)
21 #define PROFSTART 0x8000
27 #define PROFSTART 2 /* Verify This! */
30 #define PROFSTART 0x2000
35 #define SCALE_1_TO_1 0x10000L
38 extern void *malloc();
40 extern char *malloc();
45 static char *profBuf = NULL;
46 static int profBufSize;
47 static int profSig = -1;
48 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 */
95 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
96 /* Soon should handle aix profiling */
99 profBufSize = (int)&etext - PROFSTART;
100 profBuf = (char *)malloc(profBufSize);
101 if (profBuf == NULL) {
102 fprintf(stderr, "Couldn't get profiling buffer.\n");
109 /* Arrange to start and stop profiling when signo is sent. */
111 ProfileSig(int signo)
113 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
114 /* Soon should handle aix profiling */
118 signal(signo, ProfileToggle);
120 signal(profSig, SIG_DFL);
124 /* Toggle profiling. Can be called as a signal handler. */
127 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
128 /* Soon should handle aix profiling */
129 static char *onMsg = "Profiling turned on.\n";
130 static char *offMsg = "Profiling turned off; mon.out written.\n";
134 write(fileno(stdout), offMsg, strlen(offMsg));
137 write(fileno(stdout), onMsg, strlen(onMsg));