xref: /xnu-10063.121.3/tools/lldbmacros/counter.py (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1from memory import IterateZPerCPU
2from xnu import *
3
4@lldb_type_summary(['scalable_counter_t'])
5@header("Counter Value\n-------------")
6def GetSimpleCounter(counter):
7    """ Prints out the value of a percpu counter
8        params: counter: value - value object representing counter
9        returns: str - THe value of the counter as a string.
10    """
11    val = 0
12    for v in IterateZPerCPU(counter):
13        val += dereference(v)
14    return str(val)
15
16@lldb_command('showcounter')
17def ShowSimpleCounter(cmd_args=None):
18    """ Show the value of a percpu counter.
19        Usage: showcounter <address of counter>
20    """
21    if not cmd_args:
22        raise ArgumentError("Please specify the address of the counter you want to read.")
23
24    print(GetSimpleCounter(kern.GetValueFromAddress(cmd_args[0], "scalable_counter_t")))
25