FreeBSD/usr.sbin/pmcstat/pmcpl_gprof.c
/*
 * Create a gmon.out file and size it.
 */
Create a gmon.out file and size it.
Create a gmon . out file and size it .
static void
pmcstat_gmon_create_file(struct pmcstat_gmonfile *pgf,
    struct pmcstat_image *image)
{
	int fd;
	size_t count;
	struct gmonhdr gm;
	const char *pathname;
	char buffer[DEFAULT_BUFFER_SIZE];
	pathname = pmcstat_string_unintern(pgf->pgf_name);
	if ((fd = open(pathname, O_RDWR|O_NOFOLLOW|O_CREAT,
		 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
		err(EX_OSERR, "ERROR: Cannot open \"%s\"", pathname);
	gm.lpc = image->pi_start;
	gm.hpc = image->pi_end;
	gm.ncnt = (pgf->pgf_nbuckets * hc_sz) + sizeof(struct gmonhdr);
	gm.version = GMONVERSION;
	gm.profrate = 0;		
	if (args.pa_flags & FLAG_DO_WIDE_GPROF_HC)
		gm.histcounter_type = WIDEHISTCOUNTER_GMONTYPE;
	else
		gm.histcounter_type = HISTCOUNTER_GMONTYPE;
	gm.spare[0] = gm.spare[1] = 0;
	if (write(fd, &gm, sizeof(gm)) < 0)
		goto error;
	(void) memset(buffer, 0, sizeof(buffer));
	count = pgf->pgf_ndatabytes - sizeof(struct gmonhdr);
	while (count > sizeof(buffer)) {
		if (write(fd, &buffer, sizeof(buffer)) < 0)
			goto error;
		count -= sizeof(buffer);
	}
	if (write(fd, &buffer, count) < 0)
		goto error;
	(void) close(fd);
	return;
 error:
	err(EX_OSERR, "ERROR: Cannot write \"%s\"", pathname);
}
static void pmcstat_gmon_create_file ( struct pmcstat_gmonfile * pgf , struct pmcstat_image * image ) { int fd ; size_t count ; struct gmonhdr gm ; const char * pathname ; char buffer [ DEFAULT_BUFFER_SIZE ] ; pathname = pmcstat_string_unintern ( pgf -> pgf_name ) ; if ( ( fd = open ( pathname , O_RDWR | O_NOFOLLOW | O_CREAT , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ) ) < 0 ) err ( EX_OSERR , " \" \" " , pathname ) ; gm . lpc = image -> pi_start ; gm . hpc = image -> pi_end ; gm . ncnt = ( pgf -> pgf_nbuckets * hc_sz ) + sizeof ( struct gmonhdr ) ; gm . version = GMONVERSION ; gm . profrate = 0 ; if ( args . pa_flags & FLAG_DO_WIDE_GPROF_HC ) gm . histcounter_type = WIDEHISTCOUNTER_GMONTYPE ; else gm . histcounter_type = HISTCOUNTER_GMONTYPE ; gm . spare [ 0 ] = gm . spare [ 1 ] = 0 ; if ( write ( fd , & gm , sizeof ( gm ) ) < 0 ) goto error ; ( void ) memset ( buffer , 0 , sizeof ( buffer ) ) ; count = pgf -> pgf_ndatabytes - sizeof ( struct gmonhdr ) ; while ( count > sizeof ( buffer ) ) { if ( write ( fd , & buffer , sizeof ( buffer ) ) < 0 ) goto error ; count -= sizeof ( buffer ) ; } if ( write ( fd , & buffer , count ) < 0 ) goto error ; ( void ) close ( fd ) ; return ; error : err ( EX_OSERR , " \" \" " , pathname ) ; }
Create a gmon.out file and size it.
Create a gmon . out file and size it .
/* use ticks */ /* Write out the gmon header */ /* Zero fill the samples[] array */