Ejemplo n.º 1
0
void *
kstat_data_lookup(kstat_t *ksp, char *name)
{
	int i, size;
	char *namep, *datap;

	switch (ksp->ks_type) {

	case KSTAT_TYPE_NAMED:
		size = sizeof (kstat_named_t);
		namep = KSTAT_NAMED_PTR(ksp)->name;
		break;

	case KSTAT_TYPE_TIMER:
		size = sizeof (kstat_timer_t);
		namep = KSTAT_TIMER_PTR(ksp)->name;
		break;

	default:
		errno = EINVAL;
		return (NULL);
	}

	datap = ksp->ks_data;
	for (i = 0; i < ksp->ks_ndata; i++) {
		if (strcmp(name, namep) == 0)
			return (datap);
		namep += size;
		datap += size;
	}
	errno = ENOENT;
	return (NULL);
}
Ejemplo n.º 2
0
static void
save_timer(ks_returner_t *ret, kstat_t *kp, ks_instance_t *ksi)
{
	kstat_timer_t	*ktimer = KSTAT_TIMER_PTR(kp);

	SAVE_STRING(ret, ksi, ktimer, name);
	SAVE_UINT64(ret, ksi, ktimer, num_events);
	SAVE_HRTIME(ret, ksi, ktimer, elapsed_time);
	SAVE_HRTIME(ret, ksi, ktimer, min_time);
	SAVE_HRTIME(ret, ksi, ktimer, max_time);
	SAVE_HRTIME(ret, ksi, ktimer, start_time);
	SAVE_HRTIME(ret, ksi, ktimer, stop_time);
}
// It prints all the statistics related to a particular kstat
// If -l,-p option is used then it prints in different form 
// using the prefix provided as an argument to the function
void kstat_data_look(kstat_t *ksp,char* prefix,int opt)
{
        int i, size;
        char *namep;
	char *datap;
	kstat_named_t* knp;

        switch (ksp->ks_type) {

        case KSTAT_TYPE_NAMED:
                size = sizeof (kstat_named_t);
                namep = KSTAT_NAMED_PTR(ksp)->name;
                break;

        case KSTAT_TYPE_TIMER:
                size = sizeof (kstat_timer_t);
                namep = KSTAT_TIMER_PTR(ksp)->name;
                break;

        default:
                errno = EINVAL;
                return;
        } 

	
	
        datap = ksp->ks_data;
        for (i = 0; i < ksp->ks_ndata; i++) 
	{
		
		knp = kstat_data_lookup(ksp,namep);
		if(strcmp(prefix,"\0") == 0)
		{
			if(knp->data_type == KSTAT_DATA_CHAR)
				printf("        %-30.30s            %-.30s\n",namep,knp->value.c);
			else if(knp->data_type == KSTAT_DATA_INT32)
				printf("        %-30.30s            %d\n",namep,knp->value.i32);
			else if(knp->data_type == KSTAT_DATA_UINT32)
				printf("        %-30.30s            %d\n",namep,knp->value.ui32);
			else if(knp->data_type == KSTAT_DATA_INT64)
				printf("        %-30.30s            %d\n",namep,knp->value.i64);			
			else if(knp->data_type == KSTAT_DATA_UINT64)
				printf("        %-30.30s            %d\n",namep,knp->value.ui64);
			else
				printf("        %-30.30s            %s\n",namep,knp->value);
		}
		else
		{
			printf("%s",prefix);
			if(opt == 1)
				printf("%s\n",namep);
			if(opt == 2)
			{
				if(knp->data_type == KSTAT_DATA_CHAR)
					printf("%s\t%s\n",namep,knp->value.c);
				else if(knp->data_type == KSTAT_DATA_INT32)
					printf("%s\t%d\n",namep,knp->value.i32);
				else if(knp->data_type == KSTAT_DATA_UINT32)
					printf("%s\t%d\n",namep,knp->value.ui32);
				else if(knp->data_type == KSTAT_DATA_INT64)
					printf("%s\t%d\n",namep,knp->value.i64);			
				else if(knp->data_type == KSTAT_DATA_UINT64)
					printf("%s\t%d\n",namep,knp->value.ui64);
				else
					printf("%s\t%s\n",namep,knp->value);
			}
		}



                namep += size;
                datap += size;
        }
        errno = ENOENT;
        return;
}