Print this page
codereview and testing fixes.
6558 kstat: desire type for timestamps

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/stat/kstat/kstat.h
          +++ new/usr/src/cmd/stat/kstat/kstat.h
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Copyright 2013 David Hoeppner.  All rights reserved.
  24   24   * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
       25 + * Copyright 2016 Garrett D'Amore
  25   26   */
  26   27  
  27   28  #ifndef _STAT_KSTAT_H
  28   29  #define _STAT_KSTAT_H
  29   30  
  30   31  /*
  31   32   * Structures needed by the kstat reader functions.
  32   33   */
  33   34  #include <sys/var.h>
  34   35  #include <sys/utsname.h>
↓ open down ↓ 4 lines elided ↑ open up ↑
  39   40  #include <nfs/nfs.h>
  40   41  #include <nfs/nfs_clnt.h>
  41   42  
  42   43  #ifdef __sparc
  43   44  #include <vm/hat_sfmmu.h>
  44   45  #include <sys/simmstat.h>
  45   46  #include <sys/sysctrl.h>
  46   47  #include <sys/fhc.h>
  47   48  #endif
  48   49  
  49      -#define KSTAT_DATA_HRTIME       (KSTAT_DATA_STRING + 1)
  50      -
  51   50  typedef union ks_value {
  52   51          char            c[16];
  53   52          int32_t         i32;
  54   53          uint32_t        ui32;
  55   54          struct {
  56   55                  union {
  57   56                          char    *ptr;
  58   57                          char    __pad[8];
  59   58                  } addr;
  60   59                  uint32_t        len;
  61   60          } str;
  62   61  
  63   62          int64_t         i64;
  64   63          uint64_t        ui64;
       64 +        hrtime_t        t;
  65   65  } ks_value_t;
  66   66  
  67      -#define SAVE_HRTIME(I, S, N)                            \
  68      -{                                                       \
  69      -        ks_value_t v;                                   \
  70      -        v.ui64 = S->N;                                  \
  71      -        nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64);    \
       67 +#define SAVE_HRTIME(I, S, N)                                    \
       68 +{                                                               \
       69 +        ks_value_t v;                                           \
       70 +        v.ui64 = S->N;                                          \
       71 +        if (g_hrtime_fmt == KS_HRFMT_DEFAULT) {                 \
       72 +                nvpair_insert(I, #N, &v, KSTAT_DATA_UINT64);    \
       73 +        } else {                                                \
       74 +                nvpair_insert(I, #N, &v, KSTAT_DATA_TIME);      \
       75 +        }                                                       \
  72   76  }
  73   77  
  74   78  #define SAVE_INT32(I, S, N)                             \
  75   79  {                                                       \
  76   80          ks_value_t v;                                   \
  77   81          v.i32 = S->N;                                   \
  78   82          nvpair_insert(I, #N, &v, KSTAT_DATA_INT32);     \
  79   83  }
  80   84  
  81   85  #define SAVE_UINT32(I, S, N)                            \
↓ open down ↓ 26 lines elided ↑ open up ↑
 108  112          ks_value_t v;                                   \
 109  113          v.str.addr.ptr = safe_strdup(S->N);             \
 110  114          v.str.len = strlen(S->N);                       \
 111  115          nvpair_insert(I, #N, &v, KSTAT_DATA_STRING);    \
 112  116  }
 113  117  
 114  118  #define SAVE_HRTIME_X(I, N, V)                          \
 115  119  {                                                       \
 116  120          ks_value_t v;                                   \
 117  121          v.ui64 = V;                                     \
 118      -        nvpair_insert(I, N, &v, KSTAT_DATA_HRTIME);     \
      122 +        nvpair_insert(I, N, &v, KSTAT_DATA_TIME);       \
 119  123  }
 120  124  
 121  125  #define SAVE_INT32_X(I, N, V)                           \
 122  126  {                                                       \
 123  127          ks_value_t v;                                   \
 124  128          v.i32 = V;                                      \
 125  129          nvpair_insert(I, N, &v, KSTAT_DATA_INT32);      \
 126  130  }
 127  131  
 128  132  #define SAVE_UINT32_X(I, N, V)                          \
↓ open down ↓ 34 lines elided ↑ open up ↑
 163  167          "{\n\t\"module\": \"%s\",\n"                    \
 164  168          "\t\"instance\": %d,\n"                         \
 165  169          "\t\"name\": \"%s\",\n"                         \
 166  170          "\t\"class\": \"%s\",\n"                        \
 167  171          "\t\"type\": %d,\n"
 168  172  
 169  173  #define KS_DFMT "\t%-30s  "
 170  174  #define KS_JFMT "\t\t\"%s\": "
 171  175  #define KS_PFMT "%s:%d:%s:%s"
 172  176  
      177 +#define KS_HRFMT_DEFAULT        'o'
      178 +#define KS_HRFMT_BOOT           'b'
      179 +#define KS_HRFMT_UNIX           'u'
      180 +#define KS_HRFMT_DATE           'd'
      181 +#define KS_HRFMT_NANO           'n'
      182 +#define KS_HRFMT_ISO            'I'
      183 +#define KS_HRFMT_ZISO           'Z'
      184 +
 173  185  typedef struct ks_instance {
 174  186          list_node_t     ks_next;
 175  187          char            ks_name[KSTAT_STRLEN];
 176  188          char            ks_module[KSTAT_STRLEN];
 177  189          char            ks_class[KSTAT_STRLEN];
 178  190          int             ks_instance;
 179  191          uchar_t         ks_type;
 180  192          hrtime_t        ks_snaptime;
 181  193          list_t          ks_nvlist;
 182  194  } ks_instance_t;
↓ open down ↓ 87 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX