Whamcloud - gitweb
LU-12461 contrib: Add epython scripts for crash dump analysis
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / crashlib / cid / vm_table.py
1
2 """
3 Provide access to the crash's vm table.
4 Copyright 2014 Cray Inc.  All Rights Reserved
5 """
6
7 from pykdump.API import *
8
9 import crashlib.cid
10
11 class VmInfo:
12     """Make data from the crash vmtbl easily available."""
13
14     def __init__(self):
15         """Extract VM table data from crash.
16
17         Initialize the table of VM information by parsing
18         the output of the 'help -v' command.  This only extracts
19         selected data.
20
21         Each item extracted is made available as an instance attribute.
22         """
23
24         # crash 'help -v' doesn't use prefixes on numbers, so we must
25         # know what number base is in use for each numeric field.
26         decFields = ('total_pages', 'max_mapnr', 'totalram_pages',
27             'totalhigh_pages', 'num_physpages',
28             'page_hash_table_len', 'kmem_max_c_num',
29             'kmem_max_limit', 'kmem_max_cpus', 'kmem_cache_count',
30             'kmem_cache_namelen', 'kmem_cache_len_nodes', 'PG_slab',
31             'paddr_prlen', 'numnodes', 'nr_zones', 'nr_free_areas',
32             'cpu_slab_type', 'nr_swapfiles', 'ZONE_HIGHMEM',
33             'node_online_map_len', 'nr_vm_stat_items',
34             'nr_vm_event_items')
35
36         hexFields = ('flags', 'high_memory', 'vmalloc_start',
37             'mem_map', 'page_hash_table', 'PG_reserved',
38             'PG_head_tail_mask', 'slab_data', 'last_swap_read',
39             'swap_info_struct', 'mem_sec', 'mem_section')
40
41         expected_key_count = len(decFields) + len(hexFields)
42
43         for line in exec_crash_command('help -v').splitlines():
44             #               flags: 10dc52
45             #  (NODES_ONLINE|ZONES|PERCPU_KMALLOC_V2|KMEM_CACHE_INIT|SPARSEMEM|SPARSEMEM_EX|PERCPU_KMALLOC_V2_NODES|VM_STAT|VM_INIT)
46             #      kernel_pgd[NR_CPUS]: ffffffff8163f000 ...
47             #         high_memory: ffff880880000000
48             #       vmalloc_start: ffffc90000000000
49             #             mem_map: 0
50             # ...
51             #
52             # Only use the first value after the field name and
53             # only for selected fields.
54             parts = line.split()
55             if len(parts) < 2: continue
56             key = parts[0].rstrip(':')
57             if key in decFields:
58                 self.__dict__[key] = int(parts[1],10)
59             elif key in hexFields:
60                 self.__dict__[key] = int(parts[1],16)
61
62         # If some versions of crash or the kernel don't have all the
63         # fields, this check code may need to be removed or modified.
64         if len(self.__dict__.keys()) != expected_key_count:
65             raise crashlib.ida.ParseError(
66                 'Expected {:d}, but parsed {:d} entries.'.format(
67                     expected_key_count, len(self.__dict__.keys())))
68
69 # --------------------------------------------------------------------------
70
71 # Declare a shared instance.
72
73 crashlib.cid.vmtbl = VmInfo()