gperf.c 2.56 KB
/*
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
 * the contents of this file may not be disclosed to third parties, copied or
 * duplicated in any form, in whole or in part, without the prior written
 * permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to restrictions
 * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
 * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
 * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
 * rights reserved under the Copyright Laws of the United States.
 *
 *
 *	gperf - host side of profiler tool
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "gperf.h"

#ifdef __sgi
#include <a.out.h>
typedef SYMR SYMENT;
#include <ldfcn.h>
#endif


/*
 *      G l o b a l s
 */
float		Threshold = 1.0;		/* % cutoff for printing results */
unsigned int	ServerMode = 0;			/* app initiates transfer of data */
unsigned int	PrintCounts = 0;
unsigned int	PrintRealTime = 0;
char		*Namelist = "a.out";		/* namelist file */
#ifdef __sgi
LDFILE  	*Ldptr = NULL;
#endif

/*
 *  Usage message
 */
void
print_usage( char *prog)
{
    printf("usage: %s [-c] [-r] [-s] [-t threshold] a.out\n", prog);
    printf("\t-c\t\tprint raw counts\n");
    printf("\t-r\t\tprint real time\n");
    printf("\t-s\t\tserver mode\n");
    printf("\t-t threshold\tminimum %% or count to print, default 1.0\n");
    exit(0);
}


/*
 *      M a i n
 */
main(int argc, char **argv)
{
    int i;
    int c;

    while ((c = getopt(argc, argv, "t:crs")) != EOF) {
        switch (c) {
	  case 't':
	    Threshold = atof(optarg);
	    break;
	  case 's':
	    ServerMode = 1;
	    break;
	  case 'r':
	    PrintRealTime = 1;
	    break;
	  case 'c':
	    PrintCounts = 1;
	    break;
	  case '?':
	    print_usage(argv[0]);
	    break;
	}
    }
    
    if (argc - optind == 1) {
	Namelist = argv[optind];
    } else {
	print_usage(argv[0]);
    }

#ifdef __sgi
    /*
     *  Check for input errors
     */
    if ((Ldptr = ldopen(Namelist, Ldptr)) == NULL) {
	fprintf(stderr,"file = %s\n", Namelist);
	error("cannot open a.out file");
	exit(1);
    }
#endif

    if (Threshold < 0.0) {
	Threshold = 0.0;
    }

    /*
     *  Start profile server
     */
    profServerInit();

    /*
     *  Tell application to dump profile data
     */
    profServer();


}



/*
 *  Print error
 */
void
error(char *s)
{
    printf("error: %s\n", s);
    exit(1);
}