1 # include "sendmail.h" 2 3 SCCSID(@(#)stats.c 3.6 03/26/83); 4 5 /* 6 ** Statistics structure. 7 */ 8 9 struct statistics 10 { 11 time_t stat_itime; /* file initialization time */ 12 short stat_size; /* size of this structure */ 13 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 14 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 15 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 16 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 17 }; 18 19 struct statistics Stat; 20 extern long kbytes(); /* for _bf, _bt */ 21 /* 22 ** MARKSTATS -- mark statistics 23 */ 24 25 markstats(e, to) 26 register ENVELOPE *e; 27 register ADDRESS *to; 28 { 29 if (to == NULL) 30 { 31 Stat.stat_nf[e->e_from.q_mailer->m_mno]++; 32 Stat.stat_bf[e->e_from.q_mailer->m_mno] += kbytes(CurEnv->e_msgsize); 33 } 34 else 35 { 36 Stat.stat_nt[to->q_mailer->m_mno]++; 37 Stat.stat_bt[to->q_mailer->m_mno] += kbytes(CurEnv->e_msgsize); 38 } 39 } 40 /* 41 ** POSTSTATS -- post statistics in the statistics file 42 ** 43 ** Parameters: 44 ** sfile -- the name of the statistics file. 45 ** 46 ** Returns: 47 ** none. 48 ** 49 ** Side Effects: 50 ** merges the Stat structure with the sfile file. 51 */ 52 53 poststats(sfile) 54 char *sfile; 55 { 56 register int fd; 57 struct statistics stat; 58 extern long lseek(); 59 60 (void) time(&Stat.stat_itime); 61 Stat.stat_size = sizeof Stat; 62 63 fd = open(sfile, 2); 64 if (fd < 0) 65 return; 66 if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 67 stat.stat_size == sizeof stat) 68 { 69 /* merge current statistics into statfile */ 70 register int i; 71 72 for (i = 0; i < MAXMAILERS; i++) 73 { 74 stat.stat_nf[i] += Stat.stat_nf[i]; 75 stat.stat_bf[i] += Stat.stat_bf[i]; 76 stat.stat_nt[i] += Stat.stat_nt[i]; 77 stat.stat_bt[i] += Stat.stat_bt[i]; 78 } 79 } 80 else 81 bmove((char *) &Stat, (char *) &stat, sizeof stat); 82 83 /* write out results */ 84 (void) lseek(fd, 0L, 0); 85 (void) write(fd, (char *) &stat, sizeof stat); 86 (void) close(fd); 87 } 88 /* 89 ** KBYTES -- given a number, returns the number of Kbytes. 90 ** 91 ** Used in statistics gathering of message sizes to try to avoid 92 ** wraparound (at least for a while.....) 93 ** 94 ** Parameters: 95 ** bytes -- actual number of bytes. 96 ** 97 ** Returns: 98 ** number of kbytes. 99 ** 100 ** Side Effects: 101 ** none. 102 ** 103 ** Notes: 104 ** This function is actually a ceiling function to 105 ** the nearest K. 106 ** Honestly folks, floating point might be better. 107 ** Or perhaps a "statistical" log method. 108 */ 109 110 long 111 kbytes(bytes) 112 long bytes; 113 { 114 return ((bytes + 999) / 1000); 115 } 116