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