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>
17 #ifdef HAVE_SYS_FILE_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
41 static char *profBuf = NULL;
42 static int profBufSize;
43 static int profSig = -1;
44 static int profiling = 0;
54 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
55 /* Soon should handle aix profiling */
57 memset(profBuf, 0, profBufSize);
58 /* the following code is to replace the monitor call below */
59 /* monitor (PROFSTART, &etext, profBuf, profBufSize, 0); */
60 profileHeader.startpc = PROFSTART;
61 profileHeader.endpc = (afs_int32) & etext;
62 profileHeader.count = 0;
63 profil(profBuf, profBufSize, PROFSTART, SCALE_1_TO_1);
71 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
72 /* Soon should handle aix profiling */
78 f = open("mon.out", O_CREAT | O_TRUNC | O_WRONLY, 0666);
81 write(f, &profileHeader, sizeof(profileHeader));
82 write(f, profBuf, profBufSize);
87 /* Allocate the profiling buffer */
91 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
92 /* Soon should handle aix profiling */
95 profBufSize = (int)&etext - PROFSTART;
96 profBuf = malloc(profBufSize);
97 if (profBuf == NULL) {
98 fprintf(stderr, "Couldn't get profiling buffer.\n");
105 /* Arrange to start and stop profiling when signo is sent. */
107 ProfileSig(int signo)
109 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
110 /* Soon should handle aix profiling */
114 signal(signo, ProfileToggle);
116 signal(profSig, SIG_DFL);
120 /* Toggle profiling. Can be called as a signal handler. */
123 #if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
124 /* Soon should handle aix profiling */
125 static char *onMsg = "Profiling turned on.\n";
126 static char *offMsg = "Profiling turned off; mon.out written.\n";
130 write(fileno(stdout), offMsg, strlen(offMsg));
133 write(fileno(stdout), onMsg, strlen(onMsg));