예제 #1
0
def prepare_environ(args):
    if 'sea_env' in global_storage(None):
        return global_storage('sea_env')
    env = os.environ.copy()
    if args.verbose == 'info':
        env['INTEL_SEA_VERBOSE'] = '1'
    bitness = '32' if '32' in platform.architecture()[0] else '64'
    env_name = 'INTEL_LIBITTNOTIFY' + bitness
    if env_name not in env or 'SEAPI' not in env[env_name]:
        if sys.platform == 'win32':
            dl_name = 'IntelSEAPI%s.dll' % bitness
        elif sys.platform == 'darwin':
            dl_name = 'libIntelSEAPI.dylib'
        else:
            dl_name = 'libIntelSEAPI%s.so' % bitness

        env[env_name] = os.path.join(args.bindir, dl_name)
    if args.bindir not in env['PATH']:
        env['PATH'] += os.pathsep + args.bindir

    if sys.platform == 'darwin' and args.mtlshim:
        if 'DYLD_INSERT_LIBRARIES' not in env:
            env['DYLD_INSERT_LIBRARIES'] = os.path.join(
                args.bindir, 'libmtlshim.dylib')
        elif 'libmtlshim.dylib' not in env['DYLD_INSERT_LIBRARIES']:
            env['DYLD_INSERT_LIBRARIES'] += ':' + os.path.join(
                args.bindir, 'libmtlshim.dylib')
        env['ITT'] = '1'

    reset_global('sea_env', env)
    return global_storage('sea_env')
예제 #2
0
    def __init__(self, domain):
        if hasattr(self, 'lib'):
            return
        bitness = 32 if '32' in platform.architecture()[0] else 64
        env_name = 'INTEL_LIBITTNOTIFY' + str(bitness)
        self.lib = None
        self.strings = {}
        self.tracks = {}
        self.counters = {}
        env = global_storage('sea_env')
        if env_name not in env:
            print("Warning:", env_name, "is not set...")
            return
        if os.path.exists(env[env_name]):
            self.lib = cdll.LoadLibrary(env[env_name])
        if not self.lib:
            print("Warning: Failed to load", env[env_name], "...")
            return

        # void* itt_create_domain(const char* str)
        self.lib.itt_create_domain.argtypes = [c_char_p]
        self.lib.itt_create_domain.restype = c_void_p

        # void* itt_create_string(const char* str)
        self.lib.itt_create_string.argtypes = [c_char_p]
        self.lib.itt_create_string.restype = c_void_p

        # void itt_marker(void* domain, uint64_t id, void* name, int scope)
        self.lib.itt_marker.argtypes = [
            c_void_p, c_ulonglong, c_void_p, c_int, c_ulonglong
        ]

        # void itt_task_begin(void* domain, uint64_t id, uint64_t parent, void* name, uint64_t timestamp)
        self.lib.itt_task_begin.argtypes = [
            c_void_p, c_ulonglong, c_ulonglong, c_void_p, c_ulonglong
        ]

        # void itt_task_begin_overlapped(void* domain, uint64_t id, uint64_t parent, void* name, uint64_t timestamp)
        self.lib.itt_task_begin_overlapped.argtypes = [
            c_void_p, c_ulonglong, c_ulonglong, c_void_p, c_ulonglong
        ]

        # void itt_metadata_add(void* domain, uint64_t id, void* name, double value)
        self.lib.itt_metadata_add.argtypes = [
            c_void_p, c_ulonglong, c_void_p, c_double
        ]

        # void itt_metadata_add_str(void* domain, uint64_t id, void* name, const char* value)
        self.lib.itt_metadata_add_str.argtypes = [
            c_void_p, c_ulonglong, c_void_p, c_char_p
        ]

        # void itt_metadata_add_blob(void* domain, uint64_t id, void* name, const void* value, uint32_t size)
        self.lib.itt_metadata_add_blob.argtypes = [
            c_void_p, c_ulonglong, c_void_p, c_void_p, c_uint32
        ]

        # void itt_task_end(void* domain, uint64_t timestamp)
        self.lib.itt_task_end.argtypes = [c_void_p, c_ulonglong]

        # void itt_task_end_overlapped(void* domain, uint64_t timestamp, uint64_t taskid)
        self.lib.itt_task_end_overlapped.argtypes = [
            c_void_p, c_ulonglong, c_ulonglong
        ]

        # void* itt_counter_create(void* domain, void* name)
        self.lib.itt_counter_create.argtypes = [c_void_p, c_void_p]
        self.lib.itt_counter_create.restype = c_void_p

        # void itt_set_counter(void* id, double value, uint64_t timestamp)
        self.lib.itt_set_counter.argtypes = [c_void_p, c_double, c_ulonglong]

        # void* itt_create_track(const char* group, const char* track)
        self.lib.itt_create_track.argtypes = [c_char_p, c_char_p]
        self.lib.itt_create_track.restype = c_void_p

        # void itt_set_track(void* track)
        self.lib.itt_set_track.argtypes = [c_void_p]

        # uint64_t itt_get_timestamp()
        self.lib.itt_get_timestamp.restype = c_ulonglong

        if hasattr(self.lib, 'get_gpa_version'):
            # const char* get_gpa_version()
            self.lib.get_gpa_version.restype = c_char_p

        if sys.platform == 'win32':
            # const char* resolve_pointer(const char* szModulePath, uint64_t addr)
            self.lib.resolve_pointer.argtypes = [c_char_p, c_ulonglong]
            self.lib.resolve_pointer.restype = c_char_p

            # bool ExportExeIconAsGif(LPCWSTR szExePath, LPCWSTR szGifPath)
            if hasattr(self.lib, 'ExportExeIconAsGif'):
                self.lib.ExportExeIconAsGif.argtypes = [c_wchar_p, c_wchar_p]
                self.lib.ExportExeIconAsGif.restype = c_bool

                # bool ConvertToGif(LPCWSTR szImagePath, LPCWSTR szGifPath, long width, long height)
                self.lib.ConvertToGif.argtypes = [
                    c_wchar_p, c_wchar_p, c_long, c_long
                ]
                self.lib.ConvertToGif.restype = c_bool

        elif 'linux' in sys.platform:
            # void itt_write_time_sync_markers()
            self.lib.itt_write_time_sync_markers.argtypes = []

        # typedef bool (*receive_t)(void* pReceiver, uint64_t time, uint16_t count, const wchar_t** names, const wchar_t** values, double progress);
        self.receive_t = CFUNCTYPE(c_bool, c_ulonglong, c_ulonglong, c_short,
                                   POINTER(c_wchar_p), POINTER(c_wchar_p),
                                   c_double)
        # typedef void* (*get_receiver_t)(const wchar_t* provider, const wchar_t* opcode, const wchar_t* taskName);
        self.get_receiver_t = CFUNCTYPE(c_ulonglong, c_wchar_p, c_wchar_p,
                                        c_wchar_p)
        if hasattr(self.lib, 'parse_standard_source'):
            # bool parse_standard_source(const char* file, get_receiver_t get_receiver, receive_t receive)
            self.lib.parse_standard_source.argtypes = [
                c_char_p, self.get_receiver_t, self.receive_t
            ]
            self.lib.parse_standard_source.restype = c_bool

        self.domain = self.lib.itt_create_domain(domain.encode())