3 Provide access to the crash's vm table.
4 Copyright 2014 Cray Inc. All Rights Reserved
7 from pykdump.API import *
12 """Make data from the crash vmtbl easily available."""
15 """Extract VM table data from crash.
17 Initialize the table of VM information by parsing
18 the output of the 'help -v' command. This only extracts
21 Each item extracted is made available as an instance attribute.
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',
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')
41 expected_key_count = len(decFields) + len(hexFields)
43 for line in exec_crash_command('help -v').splitlines():
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
52 # Only use the first value after the field name and
53 # only for selected fields.
55 if len(parts) < 2: continue
56 key = parts[0].rstrip(':')
58 self.__dict__[key] = int(parts[1],10)
59 elif key in hexFields:
60 self.__dict__[key] = int(parts[1],16)
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())))
69 # --------------------------------------------------------------------------
71 # Declare a shared instance.
73 crashlib.cid.vmtbl = VmInfo()