dist.c revision 087e1372ab71eb8a49fbb5619711cfbb79f695fc
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <mdb/mdb_modapi.h>
#ifndef _KMDB
#include <math.h>
#endif
#include "dist.h"
/*
* Divides the given range (inclusive at both endpoints) evenly into the given
* number of buckets, adding one bucket at the end that is one past the end of
* the range. The returned buckets will be automatically freed when the dcmd
* completes or is forcibly aborted.
*/
const int *
{
int pos;
return (out);
}
/*
* We want the bins to be a constant ratio:
*
* b_0 = beg;
* b_idx = b_{idx-1} * r;
* b_buckets = end + 1;
*
* That is:
*
* buckets
* beg * r = end
*
* Which reduces to:
*
* buckets ___________________
* r = -------/ ((end + 1) / beg)
*
* log ((end + 1) / beg)
* log r = ---------------------
* buckets
*
* (log ((end + 1) / beg)) / buckets
* r = e
*/
/* ARGSUSED */
const int *
{
#ifdef _KMDB
#else
double r;
double b;
int idx = 0;
int last;
int begzero;
if (minbucketsize == 0)
minbucketsize = 1;
if (buckets == 1) {
return (out);
}
if (begzero)
beg = 1;
/*
* We've now computed r, using the previously derived formula. We
* now need to generate the array of bucket bounds. There are
* two major variables:
*
* b holds b_idx, the current index, as a double.
* last holds the integer which goes into out[idx]
*
* Our job is to transform the smooth function b_idx, defined
* above, into integer-sized buckets, with a specified minimum
* bucket size. Since b_idx is an exponentially growing function,
* any inadequate buckets must be at the beginning. To deal
* with this, we make buckets of minimum size until b catches up
* with last.
*
* A final wrinkle is that beg *can* be zero. We compute r and b
* as if beg was 1, then start last as 0. This can lead to a bit
* of oddness around the 0 bucket, but it's mostly reasonable.
*/
if (begzero)
last = 0;
int next;
b *= r;
next = (int)b;
else
last += minbucketsize;
}
return (out);
#endif
}
#define NCHARS 50
/*
* Print the distribution header with the given bucket label. The header is
* printed on a single line, and the label is assumed to fit within the given
* width (number of characters). The default label width when unspecified (0)
* is eleven characters. Optionally, a label other than "count" may be specified
* for the bucket counts.
*/
void
{
int n;
const char *dist = " Distribution ";
if (width == 0)
width = 11;
count = "count";
dashes[n] = '\0';
count);
}
/*
* Print one distribution bucket whose range is from distarray[i] inclusive to
* distarray[i + 1] exclusive by totalling counts in that index range. The
* given total is assumed to be the sum of all elements in the counts array.
* Each bucket is labeled by its range in the form "first-last" (omit "-last" if
* the range is a single value) where first and last are integers, and last is
* one less than the first value of the next bucket range. The bucket label is
* assumed to fit within the given width (number of characters), which should
* match the width value passed to dist_print_header(). The default width when
* unspecified (0) is eleven characters.
*/
void
{
int b; /* bucket range index */
int nats;
char range[40];
if (width == 0)
width = 11;
if (total == 0)
else
}