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