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