/*static char *SCCSID = "@(#)tp.c	6.1 90/11/17";*/
/*  SCCSID = @(#)tp.c 13.2 89/07/24 */

/***	tp.c - TestProfile
*
*	AUTHOR:     Benjamin W. Slivka
*
*	HISTORY:    04-May-1987 bws Initial version.
*		    15-Jun-1989 bws Produce more symbols
*
*/

#include <stdio.h>
#include <conio.h>
#include "casts.h"
#include "profile.h"

int inner(long i);
int inner1(long i);
int inner2(long i);
int inner3(long i);

#define     OUTER_LOOP	   400L  // outer loop count
#define     INNER_LOOP	   400L  // inner loop count

/*  Check return code */
#define     crc(a)  doCrc((a),__FILE__,__LINE__)

doCrc (int rc, char *file, int line)
{
    if (rc != 0) {
	printf ("%s:(%d) call failed; rc=%d\n", file, line, rc);
	exit (rc);
    }
}

main (int argc, char *argv[])
{
    long    i;
    word    unused;
    word    flags = PT_USEKP | PT_USER;
    char    *dump_file;

    if ((argc < 2) || (argc > 3)) {
	printf ("invalid parms\n");
	printf ("  usage: %s [-v] file\n", argv[0]);
	exit (1);
    }

    if (argc == 2)
	dump_file = argv[1];
    else if (strcmp(argv[1], "-v")) {
	printf("invalid parms\n");
	printf ("  usage: %s [-v] file\n", argv[0]);
	exit (1);
    } else {
	dump_file = argv[2];
	flags |= PT_VERBOSE;
    }

    crc( PROFINIT(flags, (FPC)NULL) );
    crc( PROFCLEAR(PT_USER) );
    crc( PROFON(PT_USER) );

    for (i=0; i<OUTER_LOOP; i++) {
	inner(INNER_LOOP);
	inner1(INNER_LOOP);
	inner2(INNER_LOOP);
	inner3(INNER_LOOP);
    }

    crc( PROFOFF(PT_USER) );
    crc( PROFDUMP(PT_USER, (FPC)dump_file) );
    crc( PROFFREE(PT_USER) );
}

inner(long i)
{
    long    j,k;

    for (j=0; j<i; j++)
	k=j;
}

inner1(long i)
{
    long    j,k;

    for (j=0; j<1; j++)
	k=j;
}

inner2(long i)
{
    long    j,k;

    for (j=0; j<i; j++)
	k=j;
}

inner3(long i)
{
    long    j,k;

    for (j=0; j<i; j++)
	k=j;
}
