4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <mdb/mdb_modapi.h>
28 #include <libuutil_impl.h>
30 #include <librestart_priv.h> /* instance_data_t */
35 * To count the elements of a uu_list_t without knowing its implementation, we
36 * must walk & count them.
40 inc_sz(uintptr_t addr
, const void *unknown
, void *data
)
51 startd_status(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
54 restarter_instance_list_t ril
;
55 u_longlong_t ns_total
;
57 u_longlong_t dep_inserts
, dep_cycle_ns
, dep_insert_ns
;
58 size_t graph_num
, restarter_num
;
64 uint64_t ct_from_uninit
;
65 uint64_t ct_bad_state
;
66 uint64_t ct_ovr_prefs
;
68 if (mdb_readvar(&lookups
, "dictionary_lookups") == -1) {
69 mdb_warn("failed to read 'dictionary_lookups' value\n");
73 if (mdb_readvar(&ns_total
, "dictionary_ns_total") == -1) {
74 mdb_warn("failed to read 'dictionary_ns_total' value\n");
78 if (mdb_readvar(&dep_inserts
, "dep_inserts") == -1) {
79 mdb_warn("failed to read 'dep_inserts' value\n");
83 if (mdb_readvar(&dep_cycle_ns
, "dep_cycle_ns") == -1) {
84 mdb_warn("failed to read 'dep_cycle_ns' value\n");
88 if (mdb_readvar(&dep_insert_ns
, "dep_insert_ns") == -1) {
89 mdb_warn("failed to read 'dep_insert_ns' value\n");
93 if (mdb_readvar(&dgraphp
, "dgraph") == -1) {
94 mdb_warn("failed to read 'dgraph' value\n");
99 if (mdb_pwalk("uu_list_node", inc_sz
, &graph_num
,
100 (uintptr_t)dgraphp
) == -1) {
101 mdb_warn("failed to read uu_list\n");
105 if (mdb_readvar(&ril
, "instance_list") == -1) {
106 mdb_warn("failed to read 'instance_list' value\n");
111 if (mdb_pwalk("uu_list_node", inc_sz
, &restarter_num
,
112 (uintptr_t)ril
.ril_instance_list
) == -1) {
113 mdb_warn("failed to read uu_list\n");
117 if (mdb_readvar(&ct_maint
, "stev_ct_maint") == -1) {
118 mdb_warn("failed to read 'stev_ct_maint'\n");
122 if (mdb_readvar(&ct_hwerr
, "stev_ct_hwerr") == -1) {
123 mdb_warn("failed to read 'stev_ct_hwerr'\n");
127 if (mdb_readvar(&ct_service
, "stev_ct_service") == -1) {
128 mdb_warn("failed to read 'stev_ct_service'\n");
132 if (mdb_readvar(&ct_global
, "stev_ct_global") == -1) {
133 mdb_warn("failed to read 'stev_ct_global'\n");
137 if (mdb_readvar(&ct_noprefs
, "stev_ct_noprefs") == -1) {
138 mdb_warn("failed to read 'stev_ct_noprefs'\n");
142 if (mdb_readvar(&ct_from_uninit
, "stev_ct_from_uninit") == -1) {
143 mdb_warn("failed to read 'stev_ct_from_uninit'\n");
147 if (mdb_readvar(&ct_bad_state
, "stev_ct_bad_state") == -1) {
148 mdb_warn("failed to read 'stev_ct_bad_state'\n");
152 if (mdb_readvar(&ct_ovr_prefs
, "stev_ct_ovr_prefs") == -1) {
153 mdb_warn("failed to read 'stev_ct_ovr_prefs'\n");
159 " dictionary lookups: %llu\n"
160 " average lookup time: %llu us\n"
161 " graph dependency insertions: %llu\n"
162 " average cycle-check time: %llu us\n"
163 " avg dependency insert time: %llu us\n"
164 " number of nodes in dgraph: %llu\n"
165 "number of nodes in instance_list: %llu\n"
166 "\nState Transition Events\n"
167 " maintenance: %llu\n"
168 " hardware error: %llu\n"
169 " service specific pref: %llu\n"
170 " system wide pref: %llu\n"
171 " no prefs, not raised: %llu\n"
172 " from unint, not raised: %llu\n"
173 " bad state, not raised: %llu\n"
174 " override pref, raised: %llu\n", lookups
,
175 lookups
? ns_total
/ (1000 * lookups
) : 0, dep_inserts
,
176 dep_inserts
? dep_cycle_ns
/ (1000 * dep_inserts
) : 0,
177 dep_inserts
? dep_insert_ns
/ (1000 * dep_inserts
) : 0,
178 (u_longlong_t
)graph_num
, (u_longlong_t
)restarter_num
,
179 ct_maint
, ct_hwerr
, ct_service
, ct_global
, ct_noprefs
,
180 ct_from_uninit
, ct_bad_state
, ct_ovr_prefs
);
187 xstate2chr(restarter_instance_state_t s
)
190 case RESTARTER_STATE_UNINIT
: return ('u');
191 case RESTARTER_STATE_DISABLED
: return ('d');
192 case RESTARTER_STATE_OFFLINE
: return ('0');
193 case RESTARTER_STATE_DEGRADED
: return ('D');
194 case RESTARTER_STATE_ONLINE
: return ('1');
195 case RESTARTER_STATE_MAINT
: return ('m');
196 case RESTARTER_STATE_NONE
: return ('n');
197 default: return ('?');
203 pr_instance(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
205 restarter_instance_list_t ril
;
211 if ((flags
& DCMD_ADDRSPEC
) == 0) {
212 if (mdb_readvar(&ril
, "instance_list") == -1) {
213 mdb_warn("failed to read 'instance_list' value\n");
217 if (mdb_pwalk_dcmd("uu_list_node", "instance", 0, NULL
,
218 (uintptr_t)ril
.ril_instance_list
) == -1) {
219 mdb_warn("can't walk instances\n");
226 if (mdb_vread(&ri
, sizeof (restarter_inst_t
), addr
) == -1) {
227 mdb_warn("couldn't read instance at %a\n");
231 if (DCMD_HDRSPEC(flags
))
232 mdb_printf("%-10s %-3s %1s %1s %4s\n", "ADDR", "ID", "T", "S",
235 iname
= mdb_alloc(1024, UM_SLEEP
| UM_GC
);
237 if (mdb_readstr(iname
, 1024, (uintptr_t)ri
.ri_i
.i_fmri
) == -1) {
238 mdb_warn("couldn't read instance name\n");
242 statechr
= xstate2chr(ri
.ri_i
.i_state
);
243 typechr
= (ri
.ri_i
.i_enabled
) ? 'I' : 'i';
245 mdb_printf("%-10a %3x %c %c %s\n", addr
, ri
.ri_id
, typechr
, statechr
,
253 pr_vertex(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
262 if ((flags
& DCMD_ADDRSPEC
) == 0) {
263 if (mdb_readvar(&dgraphp
, "dgraph") == -1) {
264 mdb_warn("failed to read 'dgraph' value\n");
268 if (mdb_pwalk_dcmd("uu_list_node", "vertex", 0, NULL
,
269 (uintptr_t)dgraphp
) == -1) {
270 mdb_warn("can't walk vertices");
277 if (mdb_vread(&gv
, sizeof (graph_vertex_t
), addr
) == -1) {
278 mdb_warn("couldn't read vertex at %a\n");
282 if (DCMD_HDRSPEC(flags
))
283 mdb_printf("%-10s %-3s %1s %1s %4s\n", "ADDR", "ID", "T", "S",
286 vname
= mdb_alloc(1024, UM_SLEEP
| UM_GC
);
288 if (mdb_readstr(vname
, 1024, (uintptr_t)gv
.gv_name
) == -1) {
289 mdb_warn("couldn't read vertex name\n");
295 switch (gv
.gv_type
) {
300 switch (gv
.gv_depgroup
) {
301 case DEPGRP_REQUIRE_ANY
:
304 case DEPGRP_REQUIRE_ALL
:
307 case DEPGRP_EXCLUDE_ALL
:
310 case DEPGRP_OPTIONAL_ALL
:
319 typechr
= (gv
.gv_flags
& GV_ENABLED
) ? 'I' : 'i';
320 statechr
= xstate2chr(gv
.gv_state
);
330 mdb_printf("%-10a %3x %c %c %s\n", addr
, id
, typechr
, statechr
, vname
);
337 logbuf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
343 if (mdb_lookup_by_name("logbuf", &sym
) == -1) {
344 mdb_warn("The 'logbuf' symbol is missing.\n");
348 buf
= mdb_alloc(sym
.st_size
, UM_SLEEP
| UM_GC
);
350 if (mdb_vread(buf
, sym
.st_size
, sym
.st_value
) == -1) {
351 mdb_warn("failed to read 'logbuf'\n");
355 cp
= strchr(buf
, '\0');
361 if (cp
>= buf
+ sym
.st_size
||
362 strchr(cp
+ 1, '\0') >= buf
+ sym
.st_size
) {
363 mdb_warn("'logbuf' is corrupt\n");
367 mdb_printf("%s", cp
+ 1);
368 mdb_printf("%s", buf
);
373 static const mdb_dcmd_t dcmds
[] = {
374 { "instance", NULL
, "display svc.startd restarter instance",
376 { "startd_log", NULL
, "display svc.startd debug message buffer",
378 { "startd_status", NULL
, "svc.startd status summary", startd_status
},
379 { "vertex", NULL
, "display svc.startd dependency graph vertex",
384 static const mdb_walker_t walkers
[] = {
388 static const mdb_modinfo_t modinfo
= {
389 MDB_API_VERSION
, dcmds
, walkers
392 const mdb_modinfo_t
*