Date: Fri, 10 Aug 2001 16:16:32 +0400 From: "Sergey A. Osokin" <osa@freebsd.org.ru> To: "Kenneth D. Merry" <ken@kdm.org> Cc: audit@FreeBSD.ORG Subject: Re: [PATCH] libdevstat have two compute statistics functions Message-ID: <20010810161632.A7827@freebsd.org.ru> In-Reply-To: <20010809102140.A62588@panzer.kdm.org> References: <20010808184710.A87195@freebsd.org.ru> <20010809102140.A62588@panzer.kdm.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--M9NhX3UHpAaciwkO Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu, Aug 09, 2001 at 10:21:40AM -0600, Kenneth D. Merry wrote: > On Wed, Aug 08, 2001 at 18:47:11 +0400, Sergey A. Osokin wrote: > > Hello. > > After last commit into libdevstat, devstat.c containes > > 2 compute statistics functions: old compute_stats() and > > new devstat_compute_statistics(). > > > > I believe that compute_stats() is not necessary any more > > and we should remove it. devstat_compute_statistics() is > > a superset for compute_stats(). > > This patch won't work. The reason is that the arguments to compute_stats() > can be NULL, which will cause it not to calculate that particular > statistic. OK. I mistake about goto's in switch(devstat_arg_list[metric].argtype). Look at attached patch. I make a little hack for devstat_compute_statistics(). After this patch function try to resolve all pairs of parameters. -- Rgdz, /"\ Sergey Osokin aka oZZ, \ / ASCII RIBBON CAMPAIGN osa@freebsd.org.ru X AGAINST HTML MAIL http://freebsd.org.ru/~osa/ / \ --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="patch-devstat.c" Content-Transfer-Encoding: 8bit --- src/lib/libdevstat/devstat.c.orig Fri Aug 10 11:53:40 2001 +++ src/lib/libdevstat/devstat.c Fri Aug 10 12:03:32 2001 @@ -1129,89 +1129,16 @@ long double *mb_per_second, long double *blocks_per_second, long double *ms_per_transaction) { - u_int64_t totalbytes, totaltransfers, totalblocks; - char *func_name = "compute_stats"; - - /* - * current is the only mandatory field. - */ - if (current == NULL) { - snprintf(devstat_errbuf, sizeof(devstat_errbuf), - "%s: current stats structure was NULL", - func_name); - return(-1); - } - - totalbytes = (current->bytes_written + current->bytes_read) - - ((previous) ? (previous->bytes_written + - previous->bytes_read) : 0); - - if (total_bytes) - *total_bytes = totalbytes; - - totaltransfers = (current->num_reads + - current->num_writes + - current->num_other) - - ((previous) ? - (previous->num_reads + - previous->num_writes + - previous->num_other) : 0); - if (total_transfers) - *total_transfers = totaltransfers; - - if (transfers_per_second) { - if (etime > 0.0) { - *transfers_per_second = totaltransfers; - *transfers_per_second /= etime; - } else - *transfers_per_second = 0.0; - } - - if (kb_per_transfer) { - *kb_per_transfer = totalbytes; - *kb_per_transfer /= 1024; - if (totaltransfers > 0) - *kb_per_transfer /= totaltransfers; - else - *kb_per_transfer = 0.0; - } - - if (mb_per_second) { - *mb_per_second = totalbytes; - *mb_per_second /= 1024 * 1024; - if (etime > 0.0) - *mb_per_second /= etime; - else - *mb_per_second = 0.0; - } - - totalblocks = totalbytes; - if (current->block_size > 0) - totalblocks /= current->block_size; - else - totalblocks /= 512; - - if (total_blocks) - *total_blocks = totalblocks; - - if (blocks_per_second) { - *blocks_per_second = totalblocks; - if (etime > 0.0) - *blocks_per_second /= etime; - else - *blocks_per_second = 0.0; - } - - if (ms_per_transaction) { - if (totaltransfers > 0) { - *ms_per_transaction = etime; - *ms_per_transaction /= totaltransfers; - *ms_per_transaction *= 1000; - } else - *ms_per_transaction = 0.0; - } - - return(0); + return(devstat_compute_statistics(current, previous, etime, + DSM_TOTAL_BYTES, total_bytes, + DSM_TOTAL_TRANSFERS, total_transfers, + DSM_TOTAL_BLOCKS, total_blocks, + DSM_KB_PER_TRANSFER, kb_per_transfer, + DSM_TRANSFERS_PER_SECOND, transfers_per_second, + DSM_MB_PER_SECOND, mb_per_second, + DSM_BLOCKS_PER_SECOND, blocks_per_second, + DSM_MS_PER_TRANSACTION, ms_per_transaction, + DSM_NONE)); } long double @@ -1294,6 +1221,8 @@ va_start(ap, etime); while ((metric = (devstat_metric)va_arg(ap, devstat_metric)) != 0) { + destu64 = NULL; + destld = NULL; if (metric == DSM_NONE) break; @@ -1309,34 +1238,22 @@ switch (devstat_arg_list[metric].argtype) { case DEVSTAT_ARG_UINT64: destu64 = (u_int64_t *)va_arg(ap, u_int64_t *); - if (destu64 == NULL) { - snprintf(devstat_errbuf, sizeof(devstat_errbuf), - "%s: argument type not u_int64_t * or " - "argument type missing", func_name); - retval = -1; - goto bailout; - break; /* NOTREACHED */ - } break; case DEVSTAT_ARG_LD: destld = (long double *)va_arg(ap, long double *); - if (destld == NULL) { - snprintf(devstat_errbuf, sizeof(devstat_errbuf), - "%s: argument type not long double * " - "or argument type missing", func_name); - retval = -1; - goto bailout; - break; /* NOTREACHED */ - } break; default: - snprintf(devstat_errbuf, sizeof(devstat_errbuf), - "%s: unknown argument type %d", func_name, - devstat_arg_list[metric].argtype); retval = -1; goto bailout; break; /* NOTREACHED */ } + + /* + * At this place we have already known about destination variables: + * it may be destu64 and NULL or NULL and destld, not both NULL + */ + if ((destu64 == NULL) && (destld == NULL)) + continue; /* get next arguments in while() */ switch (metric) { case DSM_TOTAL_BYTES: --M9NhX3UHpAaciwkO-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010810161632.A7827>