def __init__(self, trace_events, trace_output_dir, trace_name="bioflow_trace"): if type(trace_events) is str: trace_events = [trace_events] self.trace_events = trace_events user = getpass.getuser() trace_name = "{name}_{user}".format(name=trace_name, user=user) self.sess_name = trace_name domain = lttng.Domain() domain.type = lttng.DOMAIN_UST handle = lttng.Handle(domain=domain, session_name=trace_name) self.domain = domain self.handle = handle new_handle = trace_output_dir count = 0 while os.path.exists(new_handle): new_handle = "{trace_dir}_{cnt}".format(trace_dir=trace_output_dir, cnt=count) count += 1 trace_output_dir = new_handle os.makedirs(name=trace_output_dir, exist_ok=False) self.outdir = trace_output_dir curr_sessions = lttng.list_sessions() if trace_name in curr_sessions: lttng.destroy(trace_name) # note: this doesn't delete any files
def _create_handle(session_name: str, domain: lttng.Domain) -> lttng.Handle: """ Create a handle for a given session name and a domain, and check for errors. :param session_name: the name of the session :param domain: the domain to be used :return: the handle """ handle = None handle = lttng.Handle(session_name, domain) if handle is None: raise RuntimeError('handle creation failed') return handle
def lttng_start(events=["*"], domain_type=lttng.DOMAIN_UST): if lttng.session_daemon_alive() == 0: daemon_cmd = "lttng-sessiond --background" daemon_cmd += " --pidfile " + sessiond_pidfile subprocess.check_call(daemon_cmd, shell=True, stdout=sessiond_logfile, stderr=sessiond_logfile) lttng.destroy(session_name) ret = lttng.create_snapshot(session_name, trace_path) if ret < 0: raise RuntimeError("LTTng: " + lttng.strerror(ret)) domain = lttng.Domain() domain.type = domain_type channel = lttng.Channel() channel.name = "channel0" lttng.channel_set_default_attr(domain, channel.attr) han = lttng.Handle(session_name, domain) if han is None: raise RuntimeError("LTTng: failed to create handle") ret = lttng.enable_channel(han, channel) if ret < 0: raise RuntimeError("LTTng: " + lttng.strerror(ret)) for name in events: event = lttng.Event() event.name = name event.type = lttng.EVENT_TRACEPOINT event.loglevel = lttng.EVENT_LOGLEVEL_ALL ret = lttng.enable_event(han, event, channel.name) if ret < 0: raise RuntimeError("LTTng: " + lttng.strerror(ret)) ret = lttng.start(session_name) if ret < 0: raise RuntimeError("LTTng: " + lttng.strerror(ret))
# LTTNG-TOOLS # Making sure session does not already exist lttng.destroy(ses_name) # Creating a new session and handle ret = lttng.create(ses_name, trace_path) if ret < 0: raise LTTngError(lttng.strerror(ret)) domain = lttng.Domain() domain.type = lttng.DOMAIN_KERNEL han = None han = lttng.Handle(ses_name, domain) if han is None: raise LTTngError("Handle not created") # Enabling all events event = lttng.Event() event.type = lttng.EVENT_ALL event.loglevel_type = lttng.EVENT_LOGLEVEL_ALL ret = lttng.enable_event(han, event, None) if ret < 0: raise LTTngError(lttng.strerror(ret)) # Start, wait, stop ret = lttng.start(ses_name) if ret < 0: raise LTTngError(lttng.strerror(ret))