def METHOD_NAME(fh, events, prefilters, postfilters):
    io_tid_set = set()
    exec_tid_set = set()
    fh.write('{"traceEvents":[\n')
    # pid: fragment instance id low bits.
    # tid: pipeline driver pointer.
    def fix_io_task(ev):
        d = ev.copy()
        d.update({'pid': '0', 'tid': d['tidx'], 'name': d['cat']})
        d['ph'] = d['ph'].upper()
        d['cat'] = d['tid']
        # id: chunk source pointer.
        return d
    def fix_driver(ev):
        d = ev.copy()
        d.update({'pid': 0, 'tid': d['tidx'], 'name': d['cat'] + '_' + d['tid']})
        d['cat'] = d['tid']
        return d
    def fix_operator(ev):
        d = ev.copy()
        d.update({'pid': 0, 'tid': d['tidx']})
        return d
    for ev in events:
        name = ev.get('name')
        cat = ev.get('cat')
        d = None
        if any(f(ev) for f in prefilters): continue
        if name == 'io_task':
            d = fix_io_task(ev)
            io_tid_set.add(d['tid'])
        else:
            if name == 'process' and cat.startswith('driver'):
                d = fix_driver(ev)
            elif cat in ('pull_chunk', 'push_chunk'):
                d = fix_operator(ev)
            if d:
                exec_tid_set.add(d['tid'])
        if not d:
            continue
        remove_fields(d)
        if any(f(ev) for f in postfilters): continue
        fh.write(json.dumps(d) + ',\n')
    headers = []
    headers.append(dict(name='process_name', ph='M', pid=0, args={'name': 'starrocks_be'}))
    for tid in io_tid_set:
        d = dict(name='thread_name', ph="M", pid=0, tid=tid, args={"name": "IOThread-%s" % tid})
        headers.append(d)
    for tid in exec_tid_set:
        d = dict(name='thread_name', ph="M", pid=0, tid=tid, args={"name": "ExecThread-%s" % tid})
        headers.append(d)
    for d in headers:
        fh.write(json.dumps(d) + ',\n')
    fh.write('{}]}')