Whamcloud - gitweb
LU-12461 contrib: Add epython scripts for crash dump analysis
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / obd_devs.py
1 #!/usr/bin/env python
2
3 """
4 Copyright (c) 2015-2019 Cray Inc. All Rights Reserved.
5 Utility to display obd_devices
6 """
7
8 from pykdump.API import *
9 import argparse
10
11 from crashlib.input import toint
12 import lustrelib as ll
13 import rpc_stats as rs
14
15 description_short = "Displays the contents of global 'obd_devs'"
16
17 SEP_SIZE = 152
18 def print_separator(count):
19     s=""
20     for idx in xrange(count):
21         s += "="
22     print s
23
24 def print_header():
25     print "%-19s %-22s \t%-22s %-19s %-19s %-12s %-10s %-7s %-10s" % \
26          ("obd_device",
27           "obd_name",
28           "ip_address",
29           "client_obd",
30           "obd_import",
31           "imp_state",
32           "ish_time",
33           "index",
34           "conn_cnt")
35     print_separator(SEP_SIZE)
36
37 IMP_STATE = {
38         1:  "CLOSED",
39         2:  "NEW",
40         3:  "DISCON",
41         4:  "CONNECTING",
42         5:  "REPLAY",
43         6:  "REPLAY_LOCKS",
44         7:  "REPLAY_WAIT",
45         8:  "RECOVER",
46         9:  "FULL",
47        10:  "EVICTED",
48        11:  "IDLE"
49 }
50
51
52 def print_one_device(obd, stats_flag):
53     try:
54         nid = ll.obd2nidstr(obd)
55     except Exception, e:
56         try:
57             print "0x%-17x %-22s" % (Addr(obd), ll.obd2str(obd))
58         except Exception, e:
59             return 1
60         return 0
61
62     impstate = "--"
63     ish_time = 0
64     index=-1
65     connect_cnt = 0
66     inflight=0
67     if obd.u.cli.cl_import:
68           impstate=IMP_STATE.get(obd.u.cli.cl_import.imp_state)
69           index=obd.u.cli.cl_import.imp_state_hist_idx - 1
70           if index > 0 and index < 16:
71                 ish_time=obd.u.cli.cl_import.imp_state_hist[index].ish_time
72           inflight=obd.u.cli.cl_import.imp_inflight.counter
73           connect_cnt = obd.u.cli.cl_import.imp_conn_cnt
74
75     print "0x%-17x %-22s\t%-22s\t 0x%-17x 0x%-17x %-10s %-10d %5d %5d" % \
76           (Addr(obd),
77           ll.obd2str(obd),
78           nid,
79           Addr(obd.u.cli),
80           Addr(obd.u.cli.cl_import),
81           impstate,
82           ish_time,
83           index,
84           connect_cnt)
85     if stats_flag:
86         print
87         rs.osc_rpc_stats_seq_show(Addr(obd.u.cli))
88         print_separator(SEP_SIZE)
89     return 0
90
91 def print_devices(devices, stats_flag):
92     print_header()
93     for obd in devices:
94         if Addr(obd) == 0:
95             break
96         print_one_device(obd, stats_flag)
97     print_separator(SEP_SIZE)
98
99 def obd_devs(args):
100     if args.obd_device:
101         devices = [readSU('struct obd_device', args.obd_device)]
102     else:
103         devices = readSymbol('obd_devs')
104     print_devices(devices, args.stats_flag)
105
106 if __name__ == "__main__":
107     description = "Displays the contents of global 'obd_devs'"
108     parser = argparse.ArgumentParser(description=description)
109     parser.add_argument("obd_device", nargs="?", default = [], type=toint,
110         help="print obd_device at argument address")
111     parser.add_argument("-r", dest="stats_flag", action="count",
112         help="print the rpc_stats sequence for each client_obd")
113     args = parser.parse_args()
114     obd_devs(args)