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