Exemplo n.º 1
0
void mem_free_dhash( DHASH **d )
{
	DHASH *sd;

	if( !d || !*d )
		return;

	sd = *d;
	*d = NULL;

	*(sd->path)  = '\0';
	sd->len      = 0;
	sd->in.total = 0;
	sd->in.count = 0;
	sd->type     = 0;
	sd->valid    = 0;
	sd->empty    = 0;

	if( sd->in.points )
	{
		mem_free_point_list( sd->in.points );
		sd->in.points = NULL;
	}

	sd->proc.points = NULL;
	sd->proc.total  = 0;
	sd->proc.count  = 0;

	__mtype_free( ctl->mem->dhash, sd );
}
Exemplo n.º 2
0
void mem_free_dhash_list( DHASH *list )
{
	DHASH *d, *freed, *end;
	PTLIST *ptfree, *p;
	int j = 0;

	freed = end = NULL;
	ptfree = NULL;

	while( list )
	{
		d    = list;
		list = d->next;

		*(d->path)  = '\0';
		d->len      = 0;
		d->in.total = 0;
		d->in.count = 0;
		d->type     = 0;
		d->valid    = 0;
		d->do_pass  = 0;
		d->empty    = 0;

		if( d->in.points )
		{
			for( p = d->in.points; p->next; p = p->next );

			p->next = ptfree;
			ptfree  = d->in.points;

			d->in.points = NULL;
		}

		d->proc.points = NULL;
		d->proc.total  = 0;
		d->proc.count  = 0;

		d->next = freed;
		freed   = d;

		if( !end )
			end = d;

		j++;
	}

	__mtype_free_list( ctl->mem->dhash, j, freed, end );

	if( ptfree )
		mem_free_point_list( ptfree );
}
Exemplo n.º 3
0
int stats_report_one( DHASH *d, ST_THR *t, time_t ts, IOBUF **buf )
{
	PTLIST *list, *p;
	int i, ct, idx;
	ST_THOLD *thr;
	char *prfx;
	float sum;
	IOBUF *b;

	// grab the points list
	list = d->proc.points;
	d->proc.points = NULL;

	// count the points
	for( ct = 0, p = list; p; p = p->next )
		ct += p->count;

	// anything to do?
	if( ct == 0 )
	{
		if( list )
			mem_free_point_list( list );
		return 0;
	}

    b    = *buf;
	prfx = ctl->stats->stats->prefix;


	// if we have just one points structure, we just use
	// it's own vals array as our workspace.  We need to
	// sort in place, but only this fn holds that space
	// now, so that's ok.  If we have more than one, we
	// need a flat array, so make sure the workbuf is big
	// enough and copy each vals array into it

	if( list->next == NULL )
		t->wkspc = list->vals;
	else
	{
		// do we have enough workspace?
		if( ct > t->wkspcsz )
		{
			// double it until we have enough
			while( ct > t->wkspcsz )
				t->wkspcsz *= 2;

			// free the existing and grab a new chunk
			free( t->wkbuf );
			t->wkbuf = (float *) allocz( t->wkspcsz * sizeof( float ) );
		}

		// and the workspace is the buffer
		t->wkspc = t->wkbuf;

		// now copy the data in
		for( i = 0, p = list; p; p = p->next )
		{
			memcpy( t->wkspc + i, p->vals, p->count * sizeof( float ) );
			i += p->count;
		}
	}

	sum = 0;
	kahan_summation( t->wkspc, ct, &sum );

	// median offset
	idx = ct / 2;

	// and sort them
	qsort( t->wkspc, ct, sizeof( float ), cmp_floats );

	bprintf( "%s.count %d",  d->path, ct );
	bprintf( "%s.mean %f",   d->path, sum / (float) ct );
	bprintf( "%s.upper %f",  d->path, t->wkspc[ct-1] );
	bprintf( "%s.lower %f",  d->path, t->wkspc[0] );
	bprintf( "%s.median %f", d->path, t->wkspc[idx] );

	// variable thresholds
	for( thr = ctl->stats->thresholds; thr; thr = thr->next )
	{
		// find the right index into our values
		idx = ( thr->val * ct ) / thr->max;
		bprintf( "%s.%s %f", d->path, thr->label, t->wkspc[idx] );
	}

	mem_free_point_list( list );
	*buf = b;

	return ct;
}