Ejemplo n.º 1
0
int run_thread_test()
{
	int nthreads, nyields;
		unsigned total_switches, max_switches;
		unsigned expected_total_switches, expected_max_switches;
		for (nthreads=1; nthreads<=MAX_NTHREADS; ++nthreads)
		{
			for (nyields=0; nyields<MAX_NYIELDS; ++nyields)
			{
				threads_test_case(nthreads, nyields);

				total_switches = thread_stats(THREAD_STAT_TOTAL_SWITCHES);
				max_switches = thread_stats(THREAD_STAT_MAX_SWITCHES);
				/*every thread yields nyields times, and it's termination causes another
				 * context switch.
				 * */
				expected_total_switches = nthreads*(nyields+1);
				expected_max_switches = nthreads-1;
	//			printf("total switches: %d(expected:%d), max switches: %d(expected:%d)\n", total_switches, expected_total_switches, max_switches, expected_max_switches);
				assert( total_switches ==  expected_total_switches);
				assert( max_switches == expected_max_switches);
			}
		}
		return 0;
}
Ejemplo n.º 2
0
MemoryManager::MemoryManager() : m_enabled(false), m_checkpoint(false) {
  if (RuntimeOption::EnableMemoryManager) {
    m_enabled = true;
  }
#ifdef USE_JEMALLOC
  thread_stats(m_allocated, m_deallocated);
#endif
  resetStats();
  m_stats.maxBytes = 0;
}
Ejemplo n.º 3
0
BOOL
do_switches(ui_cmd_t* cmd, app_data_t* app_data)
{
	UNUSED(cmd);
	if (!app_data->initialized)
	{
	  printf("No data file loaded.\n");
	  return FALSE;
	}
	printf("%d\n",thread_stats(THREAD_STAT_TOTAL_SWITCHES));
	return TRUE;
}
Ejemplo n.º 4
0
BOOL
do_asw(ui_cmd_t* cmd, app_data_t* app_data)
{
	UNUSED(cmd);
	if (!app_data->initialized)
	{
	  printf("No data file loaded.\n");
	  return FALSE;
	}
	unsigned total_switches =thread_stats(THREAD_STAT_TOTAL_SWITCHES);
	printf("%f\n", (float)total_switches/(float)app_data->nthreads );
	return TRUE;
}
Ejemplo n.º 5
0
BOOL
do_sw(ui_cmd_t* cmd, app_data_t* app_data)
{
	int tid;
	if (!app_data->initialized)
	{
	  printf("No data file loaded.\n");
	  return FALSE;
	}
	if ((tid = validate_tid_param(cmd, app_data)) < 0)
	{
	  return FALSE;
	}
	printf("%d\n", thread_stats(THREAD_NONGLOBAL_STATS | tid));
	return TRUE;
}
Ejemplo n.º 6
0
caddr_t get_process_info(struct system_info *si,
                         struct process_select *sel,
                         int (*compare)())
{
    int i, j;
    int total_procs;
    int active_procs;
    struct proc *pp;
    struct task_basic_info taskInfo;
    struct thread_basic_info threadInfo;
    kern_return_t thread_status;
    kern_return_t task_status;
    int threadCount;

    /* these are copied out of sel for speed */
    int show_idle;
    int show_system;
    int show_uid;
    int show_command;

    /* get a pointer to the states summary array */
    si->procstates = process_states;

    /* set up flags which define what we are going to select */
    show_idle = sel->idle;
    show_system = sel->system;
    show_uid = sel->uid != -1;
    show_command = sel->command != NULL;

    (void) getkval(nlst[X_PROC].n_value, (int *)(&proc), sizeof(proc),
                   nlst[X_PROC].n_un.n_name);

    /* count up process states and get pointers to interesting procs */
    total_procs = 0;
    active_procs = 0;
    memset((char *)process_states, 0, sizeof(process_states));
    i = 0;
    j = 0;
    do {
        if(i == 0) {
            /* read first proc structure */
            (void) getkval(proc, (int *)&pbase[i], sizeof(struct proc), "first proc");
        } else {
            (void) getkval(pp->p_nxt, (int *)&pbase[i], sizeof(struct proc), "nxt proc");
        }
        pp = &pbase[i];

        thread_status = thread_stats(pp->p_pid, &threadInfo, &threadCount);
        task_status = task_stats(pp->p_pid, &taskInfo);
        /*
         *  Process slots that are actually in use have a non-zero
         *  status field.  Processes with SSYS set are system
         *  processes---these get ignored unless show_sysprocs is set.
         */
        if (pp->p_stat != 0 &&
                (show_system || ((pp->p_flag & SSYS) == 0)))
        {
            total_procs++;
            /* Using thread info for process states. */
            /*	    	process_states[pp->p_stat]++; */
            if(thread_status==KERN_SUCCESS)
                process_states[threadInfo.run_state]++;
            if ((pp->p_stat != SZOMB) &&
                    (show_idle || (pp->p_stat == SRUN)) &&
                    (!show_uid || pp->p_uid == (uid_t)sel->uid))
            {
                pref[j].p_self = pp;
                if(thread_status==KERN_SUCCESS)
                {
                    pref[j].run_state = threadInfo.run_state;
                    pref[j].flags = threadInfo.flags;
                    pref[j].p_pctcpu = threadInfo.cpu_usage;
                    pref[j].p_cptime = threadInfo.user_time.seconds +
                                       threadInfo.system_time.seconds;
                    pref[j].cur_priority = threadInfo.cur_priority;
                    pref[j].nthreads = threadCount;
                } else {
                    pref[j].run_state = 0;
                    pref[j].flags = 0;
                    pref[j].p_pctcpu = 0;
                    pref[j].p_cptime = 0;
                }
                /* Get processes memory usage and cputime */
                if(task_status==KERN_SUCCESS)
                {
                    pref[j].p_rsize = taskInfo.resident_size/1024;
                    pref[j].p_vsize = taskInfo.virtual_size/1024;
                } else {
                    pref[j].p_rsize = 0;
                    pref[j].p_vsize = 0;
                }
                active_procs++;
                j++;
            }
        }
        i++;
    } while(pp->p_nxt != 0);
    pref[j].p_self = NULL;  /*  End list of processes with NULL */

    /* if requested, sort the "interesting" processes */
    if (compare != NULL)
    {
        qsort((char *)pref, active_procs, sizeof(struct proc_unix), compare);
    }

    /* remember active and total counts */
    si->p_total = total_procs;
    si->p_active = pref_count = active_procs;

    /* pass back a handle */
    handle.list = pref;
    handle.count = active_procs;
    handle.current = 0;
    return((caddr_t)&handle);
}