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