Esempio n. 1
0
/* Control profiling.  Profiling is what mcount checks to see if all the
   data structures are ready.  */
static void
moncontrol (int mode)
{
  if (mode) {
    /* Start.  */
    profil ((unsigned short *) (sbuf + sizeof (struct phdr)),
	    ssiz - sizeof (struct phdr), (size_t) s_lowpc, s_scale);
    profiling = 0;
  } else {
    /* Stop.  */
    profil ((unsigned short *) 0, 0, 0, 0);
    profiling = 3;
  }
}
Esempio n. 2
0
/*
 * Control profiling
 *	profiling is what mcount checks to see if
 *	all the data structures are ready.
 */
void
moncontrol(int mode)
{
	struct gmonparam *p = &_gmonparam;

	if (mode) {
		/* start */
		profil((char *)p->kcount, p->kcountsize, p->lowpc, s_scale);
		p->state = GMON_PROF_ON;
	} else {
		/* stop */
		profil((char *)0, 0, 0, 0);
		p->state = GMON_PROF_OFF;
	}
}
Esempio n. 3
0
int main (int argc, char *argv[]) {
     double frce;
     
     input();
     inithydro();
     equili();
     initpop();

     for (istep = 1; istep <= nsteps; istep++) {
	  pbc();
	  mbc();
	  move();
	  hydrovar();
	  equili();
	  collis();
	  if (iforce)
	       force(istep, &frce);
	  if (iobst)
	       obst();
	  if (istep % ndiag == 0)
	       diag0D();
	  if (istep % nout == 0)
	       profil(istep, frce);
     }

     return 0;
}
Esempio n. 4
0
uint_t
la_objclose(uintptr_t *cookie)
{
	if (*cookie != profcookie)
		return (0);

	profcookie = 0;
	/*
	 * Turn profil() off.
	 */
	profil(0, 0, 0, 0);
	(void) munmap((caddr_t)Hptr, Fsize);
	return (0);
}
Esempio n. 5
0
EndProfiling()
{
#if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
/* Soon should handle aix profiling */
    int f;

    /* monitor(0); */
    profil(0, 0, 0, 0);
    profiling = 0;
    f = open("mon.out", O_CREAT | O_TRUNC | O_WRONLY, 0666);
    if (f <= 0)
	return;
    write(f, &profileHeader, sizeof(profileHeader));
    write(f, profBuf, profBufSize);
    close(f);
#endif
}
Esempio n. 6
0
void
StartProfiling()
{
#if !defined (AFS_AIX_ENV) && !defined (AFS_HPUX_ENV)
/* Soon should handle aix profiling */
    AllocProfBuf();
    memset(profBuf, 0, profBufSize);
    /* the following code is to replace the monitor call below  */
    /*  monitor (PROFSTART, &etext, profBuf, profBufSize, 0); */
    profileHeader.startpc = PROFSTART;
    profileHeader.endpc = (afs_int32) & etext;
    profileHeader.count = 0;
    profil(profBuf, profBufSize, PROFSTART, SCALE_1_TO_1);
    profiling = 1;
    return;
#endif
}
Esempio n. 7
0
int main()
{
    int end_address, scale, f_address, g_address, text_length;
    
    signal(SIGINT, the_end);

    end_address = (int)the_end;
    start_address = (int)main;

    text_length = (end_address - start_address + sizeof(int) - 1) / sizeof(int);
    printf("start_address 0x%x, end_address 0x%x, text_length 0x%x\n", start_address, end_address, text_length);

    f_address = (int)f;
    g_address = (int)g;
    printf("f_address 0x%x, g_address 0x%x, f_offset %d, g_offset %d\n", f_address, g_address, f_address-start_address, g_address-start_address);
    
    scale = 0xffff;
    profil(buffer, sizeof(unsigned short) * 4096, start_address, scale);

    for(;;) {
        f();
        g();
    }
}
Esempio n. 8
0
File: main.c Progetto: Mayesty/start
int main()
{
    printf("------------BIENVENUE DANS LE JEU LES CHIFFRES ET LES LETTRES----------------\n\n");
    printf("*******PARTIE 1 : LES LETTRES\n");
    printf("*******PARTIE 2 : LES CHIFFRES\n");
    printf("*******PARTIE 3 : LE DUEL\n\n");
    printf("------------VOUS ETES EN MODE ENTRAIENEMT------------------------------------\n\n");
    printf(" ____________________________________________________________________________\n\n");
    printf("            NOUS COMMENCONS PAR LA PATIE CHIFFRES                             \n\n");
    printf(" ____________________________________________________________________________\n\n");

    printf(" Le but est de trouver a travers des opérations mathématiques proposees \n");
    printf(" dans le tableau de signes, le resultat a trouver a partir des nombres\n");
    printf("  tires.Vous n'utiliserez qu'un nombre une seule fois, vous pouvez  \n");
    printf(" reutiliser les resultats de vos operations une seule fois egalement  \n");
    printf("Vous gagnez des points si votre resultat est exact au nombre a trouver \n");
    printf("ou  proche d'une difference de 5\n\n");

    printf("--------------------A VOUS DE JOUER*****BONNE CHANCE------------------------\n\n");
    printf("----------------------------------------------------------------------------\n\n\n\n\n\n\n");

    char nom[10];

    printf("Nous allons commencer par votre profil,veuillez saisir un  surnom\n\n");
    scanf("%s",nom);

  printf("\n\n");

    printf("BIENVENUE~.~%s",nom);
    Player*pPlayer=initplayer(nom);
    profil(pPlayer,nom);
    printf("\n");
    printf("PREMIER PARTIE LETTRE\n");
    printf("veuillez faire votre premier tirage\n");
    printf("vous devez tirez 10 fois une voyelle ou une consomne--\n");
    char choix;
    char*tabvoyel[80]={"AAAAEEEEEEIIIIIIIOOOOOOOUUUUUUUUUUAAAAAAAAAEEEEEEIIIIIIIOOOOOOOOUUUUUUU"};
    char*tabconso[65]={"BBBCCCDDDFFFGGGHHHJJJKKKLLLMMMNNNPPPQQQRRRSSSTTTVVVWWWXXXYYYZZZ"};
    scanf("%c",&choix);
    switch(choix)
    {
        case 'v': demande_lettre(tabvoyel[80]);
        break;
        case'c':demande_lettre(tabconso[65]);
        break;
        default:printf("veuillez entrer une lettre correcte\n");
    }

    Chiffres *pChiffres;
    pChiffres=initabchif(6);
    Results *pResults;
    pResults=initialisation_pile(6);
    printf("\n\n");

    printf("TABLEAU DE NOMBRES------RESUTAT  A TROUVER\n\n");
    affiche_tabchif(*pChiffres);

        char **operateurs;
        int i;
        int taille=3;

      operateurs=(char**)malloc(sizeof(char*)*taille);
      for(i=0; i<taille;i++)
        operateurs[i]=(char*)malloc(sizeof(char)*taille);

        int j;

        operateurs[0][0]='+';
        operateurs[0][1]='-';
        operateurs[1][0]='x';
        operateurs[1][1]='/';
        operateurs[2][1]='R';
        operateurs[2][2]='E';
          printf("\n\n");

     for(i=0;i<3;i++)
    {
        for(j=0; j<3; j++)
        {
            printf("|%2c",operateurs[i][j]);

        }
        printf("|\n");
    }
  printf("\n\n\n");
  choixope();
free(pPlayer);
free(pChiffres);
free(pResults);
























    return 0;
}
KAFFE_STD_PROF_RATE
#endif
#endif

int enableXProfiling(void)
{
	int retval = false;

	xProfilingOff();
	/* Start up our profiler and set it to observe the main executable */
	if( xProfFlag &&
	    enableProfileTimer() &&
	    (kaffe_memory_samples = createMemorySamples()) &&
	    observeMemory(kaffe_memory_samples, &_start, &etext - &_start) &&
	    (profiler_debug_file = createDebugFile(kaffe_syms_filename)) &&
	    !atexit(profilerAtExit) )
	{
#if defined(KAFFE_CPROFILER)
		struct gmonparam *gp = getGmonParam();
		int prof_rate;
#endif
		
#if defined(KAFFE_CPROFILER)
		/* Turn off any other profiling */
		profil(0, 0, 0, 0);
#if defined(KAFFE_STD_PROF_RATE)
		if( !(prof_rate = kaffeStdProfRate()) )
#endif
			prof_rate = hertz(); /* Just guess */
		if( !prof_rate )
			prof_rate = 100;
		/* Copy the hits leading up to now into our own counters */
		if( gp && gp->kcountsize > 0 )
		{
			int lpc, len = gp->kcountsize / sizeof(HISTCOUNTER);
			HISTCOUNTER *hist = gp->kcount;
			int scale;

			scale = (gp->highpc - gp->lowpc) / len;
			for( lpc = 0; lpc < len; lpc++ )
			{
				if( hist[lpc] )
				{
					char *pc = ((char *)gp->lowpc) +
						(lpc * scale);

					memoryHitCount(kaffe_memory_samples,
						       pc,
						       (100 * hist[lpc]) /
						       prof_rate);
				}
			}
		}
#endif
		retval = true;
	}
	else
	{
		xProfFlag = 0;
		disableXProfiling();
	}
	xProfilingOn();
	return( retval );
}
Esempio n. 10
0
int
CVMJITprofil(u_short *buf, size_t bufsiz, size_t offset, u_int scale)
{
    profil((char*)buf, bufsiz, offset, scale);
    return 0;
}
Esempio n. 11
0
/*
 * int (*alowpc)(), (*ahighpc)(); boundaries of text to be monitored
 * WORD *buffer;	ptr to space for monitor data(WORDs)
 * size_t bufsize;	size of above space(in WORDs)
 * size_t nfunc;	max no. of functions whose calls are counted
 *			(default nfunc is 300 on PDP11, 600 on others)
 */
void
monitor(int (*alowpc)(void), int (*ahighpc)(void), WORD *buffer,
	size_t bufsize, size_t nfunc)
{
	uint_t scale;
	long text;
	char *s;
	struct hdr *hdrp;
	ANCHOR  *newanchp;
	size_t	ssiz;
	int error;
	char	*lowpc = (char *)alowpc;
	char	*highpc = (char *)ahighpc;

	lmutex_lock(&mon_lock);

	if (lowpc == NULL) {		/* true only at the end */
		error = 0;
		if (curAnchor != NULL) { /* if anything was collected!.. */
			profil(NULL, 0, 0, 0);
			if (writeBlocks() == 0)
				error = errno;
		}
		lmutex_unlock(&mon_lock);
		if (error) {
			errno = error;
			perror(mon_out);
		}
		return;
	}

	/*
	 * Ok - they want to submit a block for immediate use, for
	 *	function call count consumption, and execution profile
	 *	histogram computation.
	 * If the block fails sanity tests, just bag it.
	 * Next thing - get name to use. If PROFDIR is NULL, let's
	 *	get out now - they want No Profiling done.
	 *
	 * Otherwise:
	 * Set the block hdr cells.
	 * Get an anchor for the block, and link the anchor+block onto
	 *	the end of the chain.
	 * Init the grabba-cell externs (countbase/limit) for this block.
	 * Finally, call profil and return.
	 */

	ssiz = ((sizeof (struct hdr) + nfunc * sizeof (struct cnt)) /
	    sizeof (WORD));
	if (ssiz >= bufsize || lowpc >= highpc) {
		lmutex_unlock(&mon_lock);
		return;
	}

	if ((s = getenv(PROFDIR)) == NULL) { /* PROFDIR not in environment */
		mon_out = MON_OUT; /* use default "mon.out" */
	} else if (*s == '\0') { /* value of PROFDIR is NULL */
		lmutex_unlock(&mon_lock);
		return; /* no profiling on this run */
	} else { /* construct "PROFDIR/pid.progname" */
		int n;
		pid_t pid;
		char *name;
		size_t len;

		len = strlen(s);
		/* 15 is space for /pid.mon.out\0, if necessary */
		if ((mon_out = libc_malloc(len + strlen(___Argv[0]) + 15))
		    == NULL) {
			lmutex_unlock(&mon_lock);
			perror("");
			return;
		}
		(void) strcpy(mon_out, s);
		name = mon_out + len;
		*name++ = '/'; /* two slashes won't hurt */

		if ((pid = getpid()) <= 0) /* extra test just in case */
			pid = 1; /* getpid returns something inappropriate */

		/* suppress leading zeros */
		for (n = 10000; n > pid; n /= 10)
			;
		for (; ; n /= 10) {
			*name++ = pid/n + '0';
			if (n == 1)
			    break;
			pid %= n;
		}
		*name++ = '.';

		if (___Argv != NULL) {	/* mcrt0.s executed */
			if ((s = strrchr(___Argv[0], '/')) != NULL)
				(void) strcpy(name, s + 1);
			else
				(void) strcpy(name, ___Argv[0]);
		} else {
			(void) strcpy(name, MON_OUT);
		}
	}


	hdrp = (struct hdr *)(uintptr_t)buffer;	/* initialize 1st region */
	hdrp->lpc = lowpc;
	hdrp->hpc = highpc;
	hdrp->nfns = nfunc;

	/* get an anchor for the block */
	newanchp = (curAnchor == NULL) ? &firstAnchor :
	    (ANCHOR *)libc_malloc(sizeof (ANCHOR));

	if (newanchp == NULL) {
		lmutex_unlock(&mon_lock);
		perror("monitor");
		return;
	}

	/* link anchor+block into chain */
	newanchp->monBuffer = hdrp;		/* new, down. */
	newanchp->next  = NULL;			/* new, forward to NULL. */
	newanchp->prior = curAnchor;		/* new, backward. */
	if (curAnchor != NULL)
		curAnchor->next = newanchp;	/* old, forward to new. */
	newanchp->flags = HAS_HISTOGRAM;	/* note it has a histgm area */

	/* got it - enable use by mcount() */
	countbase  = (char *)buffer + sizeof (struct hdr);
	_countlimit = countbase + (nfunc * sizeof (struct cnt));

	/* (set size of region 3) */
	newanchp->histSize = (int)
	    (bufsize * sizeof (WORD) - (_countlimit - (char *)buffer));


	/* done w/regions 1 + 2: setup 3  to activate profil processing. */
	buffer += ssiz;			/* move ptr past 2'nd region */
	bufsize -= ssiz;		/* no. WORDs in third region */
					/* no. WORDs of text */
	text = (highpc - lowpc + sizeof (WORD) - 1) / sizeof (WORD);

	/*
	 * scale is a 16 bit fixed point fraction with the decimal
	 * point at the left
	 */
	if (bufsize < text) {
		/* make sure cast is done first! */
		double temp = (double)bufsize;
		scale = (uint_t)((temp * (long)0200000L) / text);
	} else {
		/* scale must be less than 1 */
		scale = 0xffff;
	}
	bufsize *= sizeof (WORD);	/* bufsize into # bytes */
	profil(buffer, bufsize, (ulong_t)lowpc, scale);


	curAnchor = newanchp;	/* make latest addition, the cur anchor */
	lmutex_unlock(&mon_lock);
}
Esempio n. 12
0
int
profile_open(const char *fname, Link_map *lmp)
{
	size_t		hsize;		/* struct hdr size */
	size_t		psize;		/* profile histogram size */
	size_t		csize;		/* call graph array size */
	size_t		msize;		/* size of memory being profiled */
	int		i, fd, fixed = 0;
	caddr_t		lpc;
	caddr_t		hpc;
	caddr_t		addr;
	struct stat	status;
	int		new_buffer = 0;
	sigset_t	mask;
	int		err;
	Ehdr *		ehdr;		/* ELF header for file */
	Phdr *		phdr;		/* program headers for file */
	Dyn *		dynp = 0;	/* Dynamic section */
	Word		nsym = 0;	/* no. of symtab ntries */

	if (*Profile == '\0') {
		const char	*dir, *suf;
		char		*tmp;

		/*
		 * From the basename of the specified filename generate the
		 * appropriate profile buffer name.  The profile file is created
		 * if it does not already exist.
		 */
		if (((tmp = strrchr(fname, '/')) != 0) && (*(++tmp)))
			fname = tmp;

#if	defined(_ELF64)
		suf = MSG_ORIG(MSG_SUF_PROFILE_64);
#else
		suf = MSG_ORIG(MSG_SUF_PROFILE);
#endif
		if (dlinfo((void *)NULL, RTLD_DI_PROFILEOUT, &dir) == -1)
			dir = MSG_ORIG(MSG_PTH_VARTMP);

		(void) snprintf(Profile, MAXPATHLEN, MSG_ORIG(MSG_FMT_PROFILE),
		    dir, fname, suf);
	}

	if ((fd = open(Profile, (O_RDWR | O_CREAT), 0666)) == -1) {
		err = errno;
		(void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), Profile,
		    strerror(err));
		return (0);
	}

	/*
	 * Now we determine the valid pc range for this object.  The lpc is easy
	 * (lmp->l_addr), to determine the hpc we must examine the Phdrs.
	 */
	lpc = hpc = (caddr_t)lmp->l_addr;
	/* LINTED */
	ehdr = (Ehdr *)lpc;
	if (ehdr->e_phnum == 0) {
		(void) close(fd);
		return (0);
	}
	if (ehdr->e_type == ET_EXEC)
		fixed = 1;
	/* LINTED */
	phdr = (Phdr *)(ehdr->e_phoff + lpc);
	for (i = 0; i < ehdr->e_phnum; i++, phdr++) {
		caddr_t	_hpc;

		if (phdr->p_type == PT_DYNAMIC) {
			dynp = (Dyn *)phdr->p_vaddr;
			if (fixed == 0) {
				dynp = (Dyn *)((unsigned long)dynp +
					(unsigned long)lpc);
			}
			continue;
		}

		if (phdr->p_type != PT_LOAD)
			continue;

		_hpc = (caddr_t)(phdr->p_vaddr + phdr->p_memsz);
		if (fixed == 0) {
			_hpc = (caddr_t)((unsigned long)_hpc +
				(unsigned long)lpc);
		}
		if (_hpc > hpc)
			hpc = _hpc;
	}
	if (lpc == hpc) {
		(void) close(fd);
		return (0);
	}

	/*
	 * In order to determine the number of symbols in the object scan the
	 * dynamic section until we find the DT_HASH entry (hash[1] == symcnt).
	 */
	if (dynp) {
		for (; dynp->d_tag != DT_NULL; dynp++) {
			unsigned int	*hashp;

			if (dynp->d_tag != DT_HASH)
				continue;

			hashp = (unsigned int *)dynp->d_un.d_ptr;
			if (fixed == 0) {
				hashp = (unsigned int *)((unsigned long)hashp +
					(unsigned long)lpc);
			}
			nsym = hashp[1];
			break;
		}
	}

	/*
	 * Determine the (minimum) size of the buffer to allocate
	 */
	Lpc = lpc = (caddr_t)PRF_ROUNDWN((long)lpc, sizeof (long));
	Hpc = hpc = (caddr_t)PRF_ROUNDUP((long)hpc, sizeof (long));

	hsize = sizeof (L_hdr);
	msize = (size_t)(hpc - lpc);
	psize = (size_t)PRF_ROUNDUP((msize / PRF_BARSIZE), sizeof (long));
	csize = (nsym + 1) * PRF_CGINIT * sizeof (L_cgarc);
	Fsize = (hsize + psize + csize);

	/*
	 * If the file size is zero (ie. we just created it), truncate it
	 * to the minimum size.
	 */
	(void) fstat(fd, &status);
	if (status.st_size == 0) {
		if (ftruncate(fd, Fsize) == -1) {
			err = errno;
			(void) fprintf(stderr, MSG_INTL(MSG_SYS_FTRUNC),
			    Profile, strerror(err));
			(void) close(fd);
			return (0);
		}
		new_buffer++;
	} else
		Fsize = status.st_size;

	/*
	 * Map the file in.
	 */
	if ((addr = (caddr_t)mmap(0, Fsize, (PROT_READ | PROT_WRITE),
	    MAP_SHARED, fd, 0)) == (char *)-1) {
		err = errno;
		(void) fprintf(stderr, MSG_INTL(MSG_SYS_MMAP), Profile,
		    strerror(err));
		(void) close(fd);
		return (0);
	}
	(void) close(fd);

	/*
	 * Initialize the remaining elements of the header.  All pc addresses
	 * that are recorded are relative to zero thus allowing the recorded
	 * entries to be correlated with the symbols in the original file,
	 * and to compensate for any differences in where the file is mapped.
	 * If the high pc address has been initialized from a previous run,
	 * and the new entry is different from the original then a new library
	 * must have been installed.  In this case bale out.
	 */
	/* LINTED */
	Hptr = (L_hdr *)addr;

	if (new_buffer)
		(void) prof_mutex_init((lwp_mutex_t *)&Hptr->hd_mutex);

	(void) prof_mutex_lock((mutex_t *)&Hptr->hd_mutex, &mask);
	if (Hptr->hd_hpc) {
		if (Hptr->hd_hpc != (caddr_t)(hpc - lpc)) {
			(void) fprintf(stderr, MSG_INTL(MSG_GEN_PROFSZCHG),
			    Profile);
			(void) prof_mutex_unlock((mutex_t *)&Hptr->
			    hd_mutex, &mask);
			(void) munmap((caddr_t)Hptr, Fsize);
			return (0);
		}
	} else {
		/*
		 * Initialize the header information as we must have just
		 * created the output file.
		 */
		Hptr->hd_magic = (unsigned int)PRF_MAGIC;
#if	defined(_ELF64)
		Hptr->hd_version = (unsigned int)PRF_VERSION_64;
#else
		Hptr->hd_version = (unsigned int)PRF_VERSION;
#endif
		Hptr->hd_hpc = (caddr_t)(hpc - lpc);
		/* LINTED */
		Hptr->hd_psize = (unsigned int)psize;
		/* LINTED */
		Hptr->hd_fsize = (unsigned int)Fsize;
		Hptr->hd_ncndx = nsym;
		Hptr->hd_lcndx = (nsym + 1) * PRF_CGINIT;
	}

	(void) prof_mutex_unlock((mutex_t *)&Hptr->hd_mutex, &mask);
	/* LINTED */
	Cptr = (L_cgarc *)(addr + hsize + psize);

	/*
	 * Turn on profiling
	 */
	/* LINTED */
	profil((unsigned short *)(addr + hsize),
		psize, (unsigned long)lpc, (unsigned int) PRF_SCALE);

	return (1);
}