Print this page
XXXX Check for uninitialized kernel statistics

@@ -1205,10 +1205,48 @@
                         (void) KSTAT_UPDATE(ksp, KSTAT_WRITE);
                 }
                 ksp->ks_flags &= ~KSTAT_FLAG_DORMANT;
         }
 
+#ifdef DEBUG
+        /*
+         * Search for uninitialized kstats.
+         */
+        switch (ksp->ks_type) {
+        case KSTAT_TYPE_NAMED: {
+                uint_t i;
+                kstat_named_t *knp = KSTAT_NAMED_PTR(ksp);
+
+                for (i = 0; i < ksp->ks_ndata; i++, knp++) {
+                        if (knp->data_type > KSTAT_DATA_STRING) {
+                                cmn_err(CE_WARN,
+                                    "kstat_install('%s', %d, '%s'): "
+                                    "invalid data type",
+                                    ksp->ks_module, ksp->ks_instance,
+                                    ksp->ks_name);
+                        }
+
+                        /*
+                         * If the name of this kstat is empty
+                         * we assume it is uninitialized.
+                         */
+                        if (knp->name[0] == '\0') {
+                                cmn_err(CE_WARN,
+                                    "kstat_install('%s', %d, '%s'): "
+                                    "uninitialized kstat",
+                                    ksp->ks_module, ksp->ks_instance,
+                                    ksp->ks_name);
+                        }
+                }
+
+                break;
+        }
+        default:
+                break;
+        }
+#endif
+
         /*
          * Now that the kstat is active, make it visible to the kstat driver.
          */
         ksp->ks_flags &= ~KSTAT_FLAG_INVALID;
         kstat_rele(ksp);