From ebd42496392d4ff207a97dd664d8dbaad66425b0 Mon Sep 17 00:00:00 2001 From: Felix Frank Date: Tue, 14 Jul 2009 10:57:21 +0200 Subject: [PATCH] Move statistics keeping from afs_dcache to afs_fetchstore. More context of the afs_CacheFetchProc() call in GetDCache is now inlined in the afs_CacheFetchProc. Boosts readability of GetDCache and saves stack, as counter pointers need not be passed anymore. The statistics code is more readable due to lesser indentation. Reviewed-on: http://gerrit.openafs.org/115 Reviewed-by: Russ Allbery Tested-by: Russ Allbery --- src/afs/afs_dcache.c | 92 +--------------------------------------- src/afs/afs_fetchstore.c | 77 ++++++++++++++++++++++++++++----- src/afs/afs_prototypes.h | 12 +++--- 3 files changed, 74 insertions(+), 107 deletions(-) diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index cd23c011a..b73abf084 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -1626,13 +1626,7 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte, int doReallyAdjustSize = 0; int overWriteWholeChunk = 0; - XSTATS_DECLS; #ifndef AFS_NOSTATS - struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */ - osi_timeval_t xferStartTime, /*FS xfer start time */ - xferStopTime; /*FS xfer stop time */ - afs_size_t bytesToXfer; /* # bytes to xfer */ - afs_size_t bytesXferred; /* # bytes actually xferred */ struct afs_stats_AccessInfo *accP; /*Ptr to access record in stats */ int fromReplica; /*Are we reading from a replica? */ int numFetchLoops; /*# times around the fetch/analyze loop */ @@ -2210,90 +2204,8 @@ afs_GetDCache(register struct vcache *avc, afs_size_t abyte, setNewCallback = 1; } i = osi_Time(); - XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA); - { -#ifndef AFS_NOSTATS - xferP = - &(afs_stats_cmfullperf.rpc. - fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]); - osi_GetuTime(&xferStartTime); - - code = - afs_CacheFetchProc(tc, file, - (afs_size_t) Position, tdc, - avc, &bytesToXfer, - &bytesXferred, size, tsmall); - - osi_GetuTime(&xferStopTime); - (xferP->numXfers)++; - if (!code) { - (xferP->numSuccesses)++; - afs_stats_XferSumBytes - [AFS_STATS_FS_XFERIDX_FETCHDATA] += - bytesXferred; - (xferP->sumBytes) += - (afs_stats_XferSumBytes - [AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10); - afs_stats_XferSumBytes - [AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF; - if (bytesXferred < xferP->minBytes) - xferP->minBytes = bytesXferred; - if (bytesXferred > xferP->maxBytes) - xferP->maxBytes = bytesXferred; - - /* - * Tally the size of the object. Note: we tally the actual size, - * NOT the number of bytes that made it out over the wire. - */ - if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) - (xferP->count[0])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET1) - (xferP->count[1])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET2) - (xferP->count[2])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET3) - (xferP->count[3])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET4) - (xferP->count[4])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET5) - (xferP->count[5])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET6) - (xferP->count[6])++; - else if (bytesToXfer <= - AFS_STATS_MAXBYTES_BUCKET7) - (xferP->count[7])++; - else - (xferP->count[8])++; - - afs_stats_GetDiff(elapsedTime, xferStartTime, - xferStopTime); - afs_stats_AddTo((xferP->sumTime), elapsedTime); - afs_stats_SquareAddTo((xferP->sqrTime), - elapsedTime); - if (afs_stats_TimeLessThan - (elapsedTime, (xferP->minTime))) { - afs_stats_TimeAssign((xferP->minTime), - elapsedTime); - } - if (afs_stats_TimeGreaterThan - (elapsedTime, (xferP->maxTime))) { - afs_stats_TimeAssign((xferP->maxTime), - elapsedTime); - } - } -#else - code = - afs_CacheFetchProc(tc, file, Position, tdc, - avc, 0, 0, size, tsmall); -#endif /* AFS_NOSTATS */ - } - XSTATS_END_TIME; + code = afs_CacheFetchProc(tc, file, Position, tdc, + avc, size, tsmall); } else code = -1; diff --git a/src/afs/afs_fetchstore.c b/src/afs/afs_fetchstore.c index 94ae3491f..4e59a6d12 100644 --- a/src/afs/afs_fetchstore.c +++ b/src/afs/afs_fetchstore.c @@ -608,10 +608,6 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base, * \param abase Base offset to fetch. * \param adc Ptr to the dcache entry for the file, write-locked. * \param avc Ptr to the vcache entry for the file. - * \param abytesToXferP Set to the number of bytes to xfer. - * NOTE: This parameter is only used if AFS_NOSTATS is not defined. - * \param abytesXferredP Set to the number of bytes actually xferred. - * NOTE: This parameter is only used if AFS_NOSTATS is not defined. * \param size Amount of data that should be fetched. * \param tsmall Ptr to the afs_FetchOutput structure. * @@ -621,7 +617,6 @@ int afs_CacheFetchProc(register struct afs_conn *tc, register struct osi_file *fP, afs_size_t abase, struct dcache *adc, struct vcache *avc, - afs_size_t * abytesToXferP, afs_size_t * abytesXferredP, afs_int32 size, struct afs_FetchOutput *tsmall) { @@ -633,16 +628,28 @@ afs_CacheFetchProc(register struct afs_conn *tc, int moredata = 0; register int offset = 0; + XSTATS_DECLS; +#ifndef AFS_NOSTATS + struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */ + osi_timeval_t xferStartTime, /*FS xfer start time */ + xferStopTime; /*FS xfer stop time */ + afs_size_t bytesToXfer = 0, bytesXferred = 0; +#endif + AFS_STATCNT(CacheFetchProc); + XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA); + + code = rxfs_fetchInit(tc, avc, abase, size, &length, adc, fP, &ops, &rock); + #ifndef AFS_NOSTATS - (*abytesToXferP) = 0; - (*abytesXferredP) = 0; + xferP = + &(afs_stats_cmfullperf.rpc.fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]); + osi_GetuTime(&xferStartTime); #endif /* AFS_NOSTATS */ adc->validPos = abase; - code = rxfs_fetchInit(tc, avc, abase, size, &length, adc, fP, &ops, &rock); if ( !code ) do { if (moredata) { code = (*ops->more)(rock, &length, &moredata); @@ -665,7 +672,7 @@ afs_CacheFetchProc(register struct afs_conn *tc, moredata = 0; } #ifndef AFS_NOSTATS - (*abytesToXferP) += length; + bytesToXfer += length; #endif /* AFS_NOSTATS */ while (length > 0) { #ifdef RX_KERNEL_TRACE @@ -678,7 +685,7 @@ afs_CacheFetchProc(register struct afs_conn *tc, "after rx_Read"); #endif #ifndef AFS_NOSTATS - (*abytesXferredP) += bytesread; + bytesXferred += bytesread; #endif /* AFS_NOSTATS */ if ( code ) { afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ, @@ -705,6 +712,56 @@ afs_CacheFetchProc(register struct afs_conn *tc, if (!code) code = (*ops->close)(rock, avc, adc, tsmall); (*ops->destroy)(&rock, code); + +#ifndef AFS_NOSTATS + osi_GetuTime(&xferStopTime); + (xferP->numXfers)++; + if (!code) { + (xferP->numSuccesses)++; + afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] += bytesXferred; + (xferP->sumBytes) += + (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10); + afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF; + if (bytesXferred < xferP->minBytes) + xferP->minBytes = bytesXferred; + if (bytesXferred > xferP->maxBytes) + xferP->maxBytes = bytesXferred; + + /* + * Tally the size of the object. Note: we tally the actual size, + * NOT the number of bytes that made it out over the wire. + */ + if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) + (xferP->count[0])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) + (xferP->count[1])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) + (xferP->count[2])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) + (xferP->count[3])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) + (xferP->count[4])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) + (xferP->count[5])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) + (xferP->count[6])++; + else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) + (xferP->count[7])++; + else + (xferP->count[8])++; + + afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime); + afs_stats_AddTo((xferP->sumTime), elapsedTime); + afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime); + if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) { + afs_stats_TimeAssign((xferP->minTime), elapsedTime); + } + if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) { + afs_stats_TimeAssign((xferP->maxTime), elapsedTime); + } + } +#endif + XSTATS_END_TIME; return code; } diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index d21259631..5a53a574e 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -497,13 +497,11 @@ extern int afs_CacheStoreProc(register struct rx_call *acall, int *shouldWake, afs_size_t * abytesToXferP, afs_size_t * abytesXferredP); extern int afs_CacheFetchProc(register struct afs_conn *tc, - register struct osi_file *fP, - afs_size_t abase, struct dcache *adc, - struct vcache *avc, - afs_size_t * abytesToXferP, - afs_size_t * abytesXferredP, - afs_int32 size, - struct afs_FetchOutput *tsmall); + register struct osi_file *fP, + afs_size_t abase, struct dcache *adc, + struct vcache *avc, + afs_int32 size, + struct afs_FetchOutput *tsmall); extern void shutdown_memcache(void); -- 2.39.5