# Path: src/python/bcc/libbcc.py
# _RAW_CB_TYPE = ct.CFUNCTYPE(None, ct.py_object, ct.c_void_p, ct.c_int)
# _LOST_CB_TYPE = ct.CFUNCTYPE(None, ct.py_object, ct.c_ulonglong)
# _RINGBUF_CB_TYPE = ct.CFUNCTYPE(ct.c_int, ct.c_void_p, ct.c_void_p, ct.c_int)
# _SYM_CB_TYPE = ct.CFUNCTYPE(ct.c_int, ct.c_char_p, ct.c_ulonglong)
#     NONE = 0x0
#     CONSTANT = 0x1
#     DEREF_OFFSET = 0x2
#     DEREF_IDENT = 0x4
#     BASE_REGISTER_NAME = 0x8
#     INDEX_REGISTER_NAME = 0x10
#     SCALE = 0x20
# _USDT_CB = ct.CFUNCTYPE(None, ct.POINTER(bcc_usdt))
# _USDT_PROBE_CB = ct.CFUNCTYPE(None, ct.c_char_p, ct.c_char_p,
#                               ct.c_ulonglong, ct.c_int)
# class bcc_perf_buffer_opts(ct.Structure):
# class bcc_symbol(ct.Structure):
# class bcc_ip_offset_union(ct.Union):
# class bcc_stacktrace_build_id(ct.Structure):
# class bcc_symbol_option(ct.Structure):
# class bcc_usdt(ct.Structure):
# class bcc_usdt_location(ct.Structure):
# class BCC_USDT_ARGUMENT_FLAGS(object):
# class bcc_usdt_argument(ct.Structure):


    from collections.abc import MutableMapping
    from collections import MutableMapping
from time import strftime
from functools import reduce
from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE, _RINGBUF_CB_TYPE, bcc_perf_buffer_opts
from .utils import get_online_cpus
from .utils import get_possible_cpus
import ctypes as ct
import os
import errno
import re
import sys
        data from the bpf program. The callback will be invoked for each
        event submitted from the kernel, up to millions per second. Use
        page_cnt to change the size of the per-cpu ring buffer. The value
        must be a power of two and defaults to 8.
        """

        if page_cnt & (page_cnt - 1) != 0:
            raise Exception("Perf buffer page_cnt must be a power of two")

        for i in get_online_cpus():
            self._open_perf_buffer(i, callback, page_cnt, lost_cb, wakeup_events)

    def _open_perf_buffer(self, cpu, callback, page_cnt, lost_cb, wakeup_events):
        def raw_cb_(_, data, size):
            try:
                callback(cpu, data, size)
            except IOError as e:
                if e.errno == errno.EPIPE:
                    exit()
                else:
                    raise e
        def lost_cb_(_, lost):
            try:
                lost_cb(lost)
            except IOError as e:
                if e.errno == errno.EPIPE:
                    exit()
                else:
                    raise e
        fn = _RAW_CB_TYPE(raw_cb_)

# Path: src/python/bcc/libbcc.py
# _RAW_CB_TYPE = ct.CFUNCTYPE(None, ct.py_object, ct.c_void_p, ct.c_int)
# _LOST_CB_TYPE = ct.CFUNCTYPE(None, ct.py_object, ct.c_ulonglong)
# _RINGBUF_CB_TYPE = ct.CFUNCTYPE(ct.c_int, ct.c_void_p, ct.c_void_p, ct.c_int)
# _SYM_CB_TYPE = ct.CFUNCTYPE(ct.c_int, ct.c_char_p, ct.c_ulonglong)
#     NONE = 0x0
#     CONSTANT = 0x1
#     DEREF_OFFSET = 0x2
#     DEREF_IDENT = 0x4
#     BASE_REGISTER_NAME = 0x8
#     INDEX_REGISTER_NAME = 0x10
#     SCALE = 0x20
# _USDT_CB = ct.CFUNCTYPE(None, ct.POINTER(bcc_usdt))
# _USDT_PROBE_CB = ct.CFUNCTYPE(None, ct.c_char_p, ct.c_char_p,
#                               ct.c_ulonglong, ct.c_int)
# class bcc_perf_buffer_opts(ct.Structure):
# class bcc_symbol(ct.Structure):
# class bcc_ip_offset_union(ct.Union):
# class bcc_stacktrace_build_id(ct.Structure):
# class bcc_symbol_option(ct.Structure):
# class bcc_usdt(ct.Structure):
# class bcc_usdt_location(ct.Structure):
# class BCC_USDT_ARGUMENT_FLAGS(object):
# class bcc_usdt_argument(ct.Structure):


# Path: src/python/bcc/table.py
    from collections.abc import MutableMapping
    from collections import MutableMapping
from time import strftime
from functools import reduce
from .libbcc import lib, _RAW_CB_TYPE, _LOST_CB_TYPE, _RINGBUF_CB_TYPE, bcc_perf_buffer_opts
from .utils import get_online_cpus
from .utils import get_possible_cpus
import ctypes as ct
import os
import errno
import re
import sys

        data from the bpf program. The callback will be invoked for each
        event submitted from the kernel, up to millions per second. Use
        page_cnt to change the size of the per-cpu ring buffer. The value
        must be a power of two and defaults to 8.
        """

        if page_cnt & (page_cnt - 1) != 0:
            raise Exception("Perf buffer page_cnt must be a power of two")

        for i in get_online_cpus():
            self._open_perf_buffer(i, callback, page_cnt, lost_cb, wakeup_events)

    def _open_perf_buffer(self, cpu, callback, page_cnt, lost_cb, wakeup_events):
        def raw_cb_(_, data, size):
            try:
                callback(cpu, data, size)
            except IOError as e:
                if e.errno == errno.EPIPE:
                    exit()
                else:
                    raise e
        def lost_cb_(_, lost):
            try:
                lost_cb(lost)
            except IOError as e:
                if e.errno == errno.EPIPE:
                    exit()
                else:
                    raise e
        fn = _RAW_CB_TYPE(raw_cb_)

        lost_fn = _LOST_CB_TYPE(lost_cb_) if lost_cb else ct.cast(None, _LOST_CB_TYPE)