def METHOD_NAME(self, ticks, bufsize=0x10000):
    self.bufsize = bufsize
    if self.dbuf:
        self.u.free(self.dbuf)
    self.dbuf = self.u.malloc(bufsize)
    text = f"""
    trace:
        mov x16, x2
        add x3, x3, x2
        add x2, x2, #4
        mov x12, #-8
        mov x10, x2
        mov x6, #-1
        mov x7, #0
        ldr x8, ={self.base}
        mrs x4, CNTPCT_EL0
        isb
    1:
        ldr w15, [x16]
        cmp w15, #1
        b.eq done
        add x4, x4, x1
    2:
        mrs x5, CNTPCT_EL0
        isb
    """
    if self.div > 1:
        text += f"""
            cmp x5, x4
            b.lo 2b
        """
    for idx, pin in enumerate(self.pins.values()):
        text += f"""
        ldr w9, [x8, #{pin * 4}]
        bfi x7, x9, #{idx}, #1
        """
    if self.on_pin_change:
        text += f"""
            cmp x7, x6
            b.eq 3f
            mov x6, x7
        """
    if self.on_reg_change:
        text += f"""
            mov x11, x2
        """
    text += f"""
        str w5, [x2], #4
        str w7, [x2], #4
    """
    if self.on_reg_change:
        text += f"""
            mov x13, #0
            add x14, x12, #8
        """
    for reg in self.regs.values():
        if isinstance(reg, tuple):
            reg = reg[0]
        text += f"""
            ldr x9, ={reg}
            ldr w9, [x9]
            str w9, [x2], #4
        """
        if self.on_reg_change:
            text += f"""
                eor w15, w9, #1
                cmp x14, #0
                b.eq 4f
                ldr w15, [x14], #4
            4:
                eor w15, w15, w9
                orr w13, w13, w15
            """
    if self.on_reg_change:
        text += f"""
            cmp x13, #0
            b.ne 4f
            mov x2, x11
            mov x11, x12
            b 3f
        4:
        """
    text += f"""
        mov x12, x11
        cmp x2, x3
        b.hs done
    3:
        sub x0, x0, #1
        cbnz x0, 1b
    done:
        sub x0, x2, x10
        ret
    """
    code = asm.ARMAsm(text, self.cbuf)
    self.iface.writemem(self.cbuf, code.data)
    self.p.dc_cvau(self.cbuf, len(code.data))
    self.p.ic_ivau(self.cbuf, len(code.data))
    self.p.write32(self.dbuf, 0)
    self.p.smp_call(self.cpu, code.trace | REGION_RX_EL1, ticks, self.div, self.dbuf, bufsize - (8 + 4 * len(self.regs)))