mon.c revision 5d54f3d8999eac1762fe0a8c7177d20f1f201fae
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1989 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Environment variable PROFDIR added such that:
* If PROFDIR doesn't exist, "mon.out" is produced as before.
* If PROFDIR = NULL, no profiling output is produced.
* If PROFDIR = string, "string/pid.progname" is produced,
* where name consists of argv[0] suitably massaged.
*/
#include "mon.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define PROFDIR "PROFDIR"
void monitor(char *, char *, char *, int, int);
void moncontrol(int);
int numctrs;
int profiling;
static struct mondata {
char *s_sbuf;
int s_bufsiz;
int s_scale;
int s_lowpc;
char mon_out[MAXPATHLEN];
#define MSG "No space for monitor buffer(s)\n"
static struct mondata *
_mondata(void)
{
if (d == 0) {
if ((d = (struct mondata *)
return (NULL);
}
mondata = d;
}
return (d);
}
void
{
int monsize;
char *buffer;
int cntsiz;
char *_alloc_profil_buf();
if (buffer == (char *)-1) {
return;
}
}
/*
* Arguments
* lowpc, hightpc: boundaries of text to be monitored
* buf: ptr to space for monitor data (WORDs)
* bufsiz: size of above space (in WORDs)
* cntsiz: max no. of functions whose calls are counted
*/
void
{
int o;
static int ssiz;
static char *sbuf;
char *s, *name;
moncontrol(0);
int pid, n;
"PROFDIR/pid.progname" */
/* set name to end of PROFDIR */
; /* suppress leading zeros */
for ( ; ; n /= 10) {
if (n == 1)
break;
pid %= n;
}
*name++ = '.';
}
if (o >= 0)
close(o);
}
return;
}
return; /* buffer too small or PC range bad */
else if (*s == '\0') /* value of PROFDIR is NULL */
return; /* no profiling on this run */
else { /* set up mon_out and progname to construct
"PROFDIR/pid.progname" when done profiling */
while (*s != '\0') /* copy PROFDIR value (path-prefix) */
*name++ = *s++;
else
}
buf += o;
bufsiz -= o;
if (bufsiz <= 0)
return;
if(bufsiz < o)
o = ((float) bufsiz / o) * 65536;
else
o = 65536;
d->s_scale = o;
moncontrol(1);
}
/*
* Control profiling
* profiling is what mcount checks to see if
* all the data structures are ready.
*/
void
moncontrol(int mode)
{
if (mode) {
/* start */
profiling = 0;
} else {
/* stop */
profil((char *)0, 0, 0, 0);
profiling = 3;
}
}