xref: /xnu-10063.101.15/tools/lldbmacros/counter.py (revision 94d3b452840153a99b38a3a9659680b2a006908e)
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