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