From:	ADVAX::"mcnc!VM1.NoDak.EDU!fac2%DAYTON.SAIC.COM" "Earle Ake" 16-FEB-1991 10:20:11.73
To:	Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
CC:	
Subj:	Re: Patch to NNTP_XMIT.C to get transfer stats

Received: by ADVAX.DECnet (utk-mail11 v1.5) ; Sat, 16 Feb 91 10:19:24 EST
Received:  from mcnc by ge-dab.GE.COM (5.61/GE-DAB 1.15) with UUCP
	id AA18991 for ; Sat, 16 Feb 91 09:34:28 -0500
Received: from VM1.NoDak.EDU by mcnc.mcnc.org (5.59/MCNC/6-11-90)
	id AA14699; Sat, 16 Feb 91 07:04:45 -0500
	for ARISIA.DNET.ge.com!EVERHART
Message-Id: <9102161204.AA14699@mcnc.mcnc.org>
Received: from NDSUVM1.BITNET by VM1.NoDak.EDU (IBM VM SMTP R1.2.1MX) with BSMTP id 9607; Sat, 16 Feb 91 06:04:18 CST
Received: from NDSUVM1.BITNET by NDSUVM1.BITNET (Mailer R2.07) with BSMTP id
 6563; Sat, 16 Feb 91 06:04:16 CST
Date:         Fri, 15 Feb 91 19:41:54 GMT
Reply-To: Earle Ake <mcnc!VM1.NoDak.EDU!fac2%DAYTON.SAIC.COM>
Sender: ANU-NEWS Discussion <ANU-NEWS@VM1.NoDak.EDU>
From: Earle Ake <mcnc!VM1.NoDak.EDU!fac2%DAYTON.SAIC.COM>
Subject:      Re: Patch to NNTP_XMIT.C to get transfer stats
To: Multiple recipients of list ANU-NEWS <ANU-NEWS@NDSUVM1>
 
        Since I originally posted the patch, Bill Glass sent me a routine
that would track the system clock in (0.01) second increments to provide a
more accurate reading than using seconds to track the elapsed time.  Here is
a newer version of the same patch I posted a few days ago which is more
accurate for sites with very high baud rates.
 
 
Earle
_____________________________________________________________________________
             ____ ____    ___
Earle Ake   /___ /___/ / /     Science Applications International Corporation
           ____//   / / /__                 Dayton, Ohio
-----------------------------------------------------------------------------
Internet: fac2@dayton.saic.com             uucp: dayvb!fac2
 
 
*** [-.old_src]nntp_xmit.c
--- nntp_xmit.c
**************
*** 277,283
  }
 
 
 
 
 
 
 
 
 
 
  /*
!  * manager_say_stop
   *
   * Check for the /sys/exec logical name NEWS_STOP being defined
   */
--- 277,283 -----
  }
 
 
 
 
 
 
 
 
 
 
  /*
!  * elapsed_time
   *
   * get the elapsed time in hundredths (0.01) of seconds
   *
**************
*** 279,284
  /*
   * manager_say_stop
   *
   * Check for the /sys/exec logical name NEWS_STOP being defined
   */
 
--- 279,312 -----
  /*
   * elapsed_time
   *
+  * get the elapsed time in hundredths (0.01) of seconds
+  *
+  * usage:
+  *
+  *   elapsed_time(1); will perform a 'start-the-clock'
+  *
+  *   elapsed_time(0); returns the number of centi-seconds since the last
+  *     'start-the-clock' command
+  */
+ #include      timeb
+
+ static int elapsed_time(update)
+ int update;
+ {
+   int result;
+   static struct timeb rbefore,rafter;
+
+   ftime(&rafter);
+   result = 100 * (rafter.time - rbefore.time) +
+     ((int) rafter.millitm - (int) rbefore.millitm) / 10;
+   if (update) rbefore = rafter;
+   return (result);
+ }
+
+
 
 
 
 
 
 
 
 
 
+ /*
+  * manager_say_stop
+  *
   * Check for the /sys/exec logical name NEWS_STOP being defined
   */
 
**************
*** 903,908
    unsigned short len, qual_len;
    FILE *fpr, *fpi, *fpl, *fpw;
    $DESCRIPTOR(qual_dsc,qual);
 
    *taskstr = '\0';
    *node = *proto = *idfile = *logfile = *dbgfile = '\0';
--- 931,938 -----
    unsigned short len, qual_len;
    FILE *fpr, *fpi, *fpl, *fpw;
    $DESCRIPTOR(qual_dsc,qual);
+   long bytes_sent = 0, total_bytes_sent = 0;
+   int total_elapsed_time = 0;
 
    *taskstr = '\0';
    *node = *proto = *idfile = *logfile = *dbgfile = '\0';
**************
*** 1190,1195
        if (debugging) fprintf(fpd,"\n");
        continue;
        }
      while (fgets(inpline0,512,fpi)) {
        char *t;
        if (*inpline0 == '.') memmove(inpline0 + 1,inpline0,strlen(inpline0) + 1
);
--- 1220,1227 -----
        if (debugging) fprintf(fpd,"\n");
        continue;
        }
+     bytes_sent = 0;
+     elapsed_time(1);
      while (fgets(inpline0,512,fpi)) {
        char *t;
        if (*inpline0 == '.') memmove(inpline0 + 1,inpline0,strlen(inpline0) + 1
);
**************
*** 1195,1200
        if (*inpline0 == '.') memmove(inpline0 + 1,inpline0,strlen(inpline0) + 1
);
        if (t = strchr(inpline0,'\n')) *t = '\0';
        if (!nntp_write(inpline0)) GO_DIE(ERROR)
        }
      fclose(fpi);
      if (!nntp_write(".") || (!(reply = wait_net_response(CLIENT_TIMER,1)))) GO
_DIE(ERROR)
--- 1227,1233 -----
        if (*inpline0 == '.') memmove(inpline0 + 1,inpline0,strlen(inpline0) + 1
);
        if (t = strchr(inpline0,'\n')) *t = '\0';
        if (!nntp_write(inpline0)) GO_DIE(ERROR)
+       bytes_sent += strlen(inpline0);
        }
      fclose(fpi);
      if (!nntp_write(".") || (!(reply = wait_net_response(CLIENT_TIMER,1)))) GO
_DIE(ERROR)
**************
*** 1198,1203
        }
      fclose(fpi);
      if (!nntp_write(".") || (!(reply = wait_net_response(CLIENT_TIMER,1)))) GO
_DIE(ERROR)
      if (debugging) fprintf(fpd," %d\n",reply);
      if (reply == 435  || reply == 437) {
        rejected++;
--- 1231,1238 -----
        }
      fclose(fpi);
      if (!nntp_write(".") || (!(reply = wait_net_response(CLIENT_TIMER,1)))) GO
_DIE(ERROR)
+     total_bytes_sent += bytes_sent;
+     total_elapsed_time += elapsed_time(0);
      if (debugging) fprintf(fpd," %d\n",reply);
      if (reply == 435  || reply == 437) {
        rejected++;
**************
*** 1228,1234
    if (logging){
      dat();
      fpl = fopen(logfile,"a+");
!     fprintf(fpl,"%s %s: nntpxmit: %s %d offered %d accepted %d rejected %d fai
led %d expired\n",
                datum, lhost, node, offered, accepted, rejected, failed, expired
);
      fclose(fpl);
      }
--- 1263,1269 -----
    if (logging){
      dat();
      fpl = fopen(logfile,"a+");
!     fprintf(fpl,"%s %s: nntpxmit: %s\n  %d offered %d accepted %d rejected %d
failed %d expired\n",
                datum, lhost, node, offered, accepted, rejected, failed, expired
);
      if (elapsed_time > 0) {
      fprintf(fpl,"Transferred %d bytes in %.2f seconds",
**************
*** 1230,1235
      fpl = fopen(logfile,"a+");
      fprintf(fpl,"%s %s: nntpxmit: %s %d offered %d accepted %d rejected %d fai
led %d expired\n",
                datum, lhost, node, offered, accepted, rejected, failed, expired
);
      fclose(fpl);
      }
    if (debugging) fclose(fpd);
--- 1265,1276 -----
      fpl = fopen(logfile,"a+");
      fprintf(fpl,"%s %s: nntpxmit: %s\n  %d offered %d accepted %d rejected %d
failed %d expired\n",
                datum, lhost, node, offered, accepted, rejected, failed, expired
);
+     if (elapsed_time > 0) {
+     fprintf(fpl,"Transferred %d bytes in %.2f seconds",
+               total_bytes_sent, (float)total_elapsed_time/100.);
+     fprintf(fpl," = %d bytes/Second\n",
+               (total_bytes_sent*100)/total_elapsed_time);
+     }
      fclose(fpl);
      }
    if (debugging) fclose(fpd);
