home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume41 / rperf / part02 / rperf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-19  |  4.4 KB  |  176 lines

  1. /**
  2.  * This program may be copied, redistributed in any form,
  3.  * source or binary, and used for any purpose, provided
  4.  * this copyright notice is retained.
  5.  *  @(#)rperf.h    3.1 12/15/93 (c) Copyright Brian P. Fitzgerald
  6.  *  Rensselaer Polytechnic Institute
  7.  **/
  8.  
  9. #ifndef PORTMAP
  10. #define PORTMAP
  11. /**
  12.  * ... so that for Solaris 2, in <rpc/clnt.h>
  13.  * we include <rpc/clnt_soc.h>, which declares clntudp_create()
  14. **/
  15. #endif                /* !PORTMAP */
  16. /**
  17.  * <rpc/rpc.h>    includes <rpc/types.h>
  18.  * <rpc/types.h>  includes <sys/types.h>
  19.  * <rpc/types.h>  includes <sys/time.h>
  20.  * <rpc/types.h>  ifndef KERNEL includes <malloc.h>
  21.  * <rpc/rpc.h>    includes <netinet/in.h>
  22.  * (I hope!)
  23. **/
  24. #include <rpc/rpc.h>
  25. #include <rpc/pmap_clnt.h>    /* declare clnt_broadcast() */
  26. #include "rstat.h"
  27.  
  28. #include <time.h>
  29. #include <stdio.h>
  30. #include <signal.h>
  31. #include <string.h>
  32. #include <ctype.h>
  33. #include <sys/socket.h>
  34.  
  35. #include <arpa/inet.h>
  36. #include <netdb.h>
  37.  
  38. /**
  39.  * The C library hsearch on some systems is incompatible.
  40.  * Use the hsearch that came with this package.
  41. **/
  42. #include "hsearch.h"
  43.  
  44. #ifdef HAVE_SYS_RESOURCE_H
  45. #include <sys/resource.h>
  46. #endif                /* HAVE_SYS_RESOURCE_H */
  47. #ifdef RLIMIT_NOFILE
  48. #define Rlimit rlimit
  49. #else                /* !RLIMIT_NOFILE */
  50. struct Rlimit {
  51.     int             rlim_cur;    /* current (soft) limit */
  52.     int             rlim_max;    /* maximum value for rlim_cur */
  53. };
  54. #endif                /* !RLIMIT_NOFILE */
  55.  
  56. typedef statsvar stats_default;
  57.  
  58. #define STATS_CONVERT(version) (stats_convert[(version)-1])
  59.  
  60. #define EACH_RESULT(version) (each_result_vers[(version)-1])
  61.  
  62. #define XDR_STATSPROC(version) (xdr_statsproc[(version)-1])
  63.  
  64. union stats_all {
  65.     struct stats    s1;
  66.     struct statsswtch s2;
  67.     struct statstime s3;
  68.     struct statsvar s4;
  69. };
  70. typedef union stats_all stats_all;
  71.  
  72. /**
  73.  * the server's rpc.rstatd reports cp_time as clock ticks since boot time
  74.  * (cumulative), or clock ticks since the previous query (incremental).
  75. **/
  76. enum cp_time_kind {
  77.     CP_TIME_CUM,        /* Sun ... */
  78.     CP_TIME_INC            /* IBM ... */
  79. };
  80. typedef enum cp_time_kind cp_time_kind;
  81.  
  82. struct hash_info {
  83.     struct in_addr  ident_addr;
  84.     struct data    *datap;
  85. };
  86. typedef struct hash_info hash_info;
  87.  
  88. struct data {
  89.     struct data    *datap;
  90.     u_long          nn;
  91.     u_long          no;
  92.     struct in_addr  addr;
  93.     char           *host;
  94.     char           *host_dup;
  95.     CLIENT         *cl;
  96.     u_long          clnt_vers;
  97.     u_long          bcst_vers;
  98.     u_long          ok_to_call;
  99.     stats_default   sn;
  100.     stats_default   so;
  101.     stats_default   sd;        /* delta or rate.  uptime = sd.boottime */
  102.     cp_time_kind    cp_kind;
  103. };
  104. extern struct data *dp;
  105.  
  106. struct array {
  107.     u_int           len;
  108.     int            *val;
  109. };
  110. typedef struct array array;
  111.  
  112. /* <sys/dk.h> */
  113. #define CP_USER         0
  114. #define CP_NICE         1
  115. #define CP_SYS          2
  116. #define CP_IDLE         3
  117.  
  118. #define cpu(dt) (dcpu ? ((dt) * 100 + hdcpu ) / dcpu : 0)
  119. #define loadav(nrun) ( (float) (nrun) / FSCALE )
  120. #define delta(x) ((*dpp)->sn.x - (*dpp)->so.x)    /* use this macro with care */
  121. #define rate(x)    (dt ? ((x) * 1000L + hdt ) / dt : 0)
  122.  
  123. #define t_d(j) tbl[(j)].dp->sd
  124. #define t_o(j) tbl[(j)].dp->so
  125. #define t_n(j) tbl[(j)].dp->sn
  126.  
  127. struct key {
  128.     char           *k_name;
  129.     int             k_noffset;
  130.     int             k_doffset;
  131.     int             k_flag;
  132.     int             k_index;
  133. };
  134. typedef struct key key;
  135.  
  136. #define        K_DELTA 0x1    /* need delta before sorting */
  137. #define        K_NZERO 0x2    /* must be nonzero for sorting */
  138. #define        K_ARRAY    0x4    /* the member is an xdr_array */
  139.  
  140. /* C faq */
  141. #ifndef offsetof
  142. #define offsetof(type, mem) ((size_t) \
  143.         ((char *)&((type *) 0)->mem - (char *)((type *) 0)))
  144. #endif                /* !offsetof */
  145. #define sd_offset(mem) offsetof(struct data,sd.mem)
  146. #define sn_offset(mem) offsetof(struct data,sn.mem)
  147.  
  148. #define AV1    0
  149. #define AV5    1
  150. #define AV15    2
  151.  
  152. struct datatbl {
  153.     int             val;
  154.     struct data    *dp;
  155. };
  156.  
  157. #define    P_DATA    0
  158. #define    P_UP    1
  159.  
  160. #define cp_val cp_time.cp_time_val
  161. #define cp_len cp_time.cp_time_len
  162. #define dk_val dk_xfer.dk_xfer_val
  163. #define dk_len dk_xfer.dk_xfer_len
  164.  
  165. #define MODE_BCST 0        /* no host args were supplied. */
  166. #define MODE_CALL 1        /* one or more host args was supplied. */
  167. extern unsigned long mode;
  168. extern unsigned long thiscount;
  169. extern unsigned long nhosts;
  170.  
  171. struct data    *new_host();
  172. void            create_array();
  173. void            destroy_array();
  174. void            doclnt_calls();
  175. void            do_broadcast();
  176.