예제 #1
0
def start_tracing_binding(tracename, tracepoints = None):
    os.remove('lttng.out')
    lttng.create(tracename, "/home/mogeb/git/benchtrace/trace-client")
    domain = lttng.Domain()
    domain.type = lttng.DOMAIN_KERNEL
    handle = lttng.Handle(tracename, domain)
    lttng.channel_set_default_attr
    lttng.list_tracepoints(handle)
    event = lttng.Event()
    event.name = 'empty_ioctl_1b'
    #event.name = 'getuid'
    #event.type = lttng.EVENT_SYSCALL
    lttng.enable_event(handle, event, None)
    lttng.start(tracename)
예제 #2
0
def _enable_events(
    handle: lttng.Handle,
    events_list: List[lttng.Event],
    channel_name: str,
) -> None:
    """
    Enable events list for a given handle and channel name, and check for errors.

    :param handle: the handle to be used
    :param events_list: the list of events to enable
    :param channel_name: the name of the channel to associate
    """
    for event in events_list:
        result = lttng.enable_event(handle, event, channel_name)
        if result < 0:
            raise RuntimeError(
                f'event enabling failed: {lttng.strerror(result)}')
	def __init__(self, sess_type, **kwargs):
		self.name = 'untitled_'+sess_type if kwargs.get('name')==None else kwargs.get('name')
		self.path = '/lttng-traces/'+self.name if kwargs.get('path')==None else kwargs.get('path')+'/'+self.name
		# Making sure session does not already exist
		lttng.destroy(self.name)
		#Creating LTTng session domain
		self.domain = lttng.Domain()
		if sess_type=='kernel':
			self.domain.type = lttng.DOMAIN_KERNEL
		elif sess_type=='ust':
			self.domain.type = lttng.DOMAIN_UST
		else:
			print("invalid tracing session type '%r', session not created" %(sess_type))
		#Enabling channel
		self.channel = lttng.Channel()
		self.channel.name="channel_1"
		self.channel.attr.overwrite = 0
		self.channel.attr.subbuf_size = 4096
		self.channel.attr.num_subbuf = 8
		self.channel.attr.switch_timer_interval = 0
		self.channel.attr.read_timer_interval = 200
		self.channel.attr.output = lttng.EVENT_MMAP
		#creating handle
		self.handle = None
		self.handle = lttng.Handle(self.name, self.domain)
		if self.handle is None:
			raise LTTngError("Handle not created")
		#creating session
		ret = lttng.create(self.name,self.path)
		if ret < 0:
			raise LTTngError(lttng.strerror(ret))
		#enabling channel on handle
		lttng.enable_channel(self.handle, self.channel)
		# Enabling all events
		self.event = lttng.Event()
		self.event.type = lttng.EVENT_ALL
		self.event.loglevel_type = lttng.EVENT_LOGLEVEL_ALL
		print
		ret = lttng.enable_event(self.handle, self.event, self.channel.name)
		if ret < 0:
			raise LTTngError(lttng.strerror(ret))
예제 #4
0
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))
예제 #5
0
    def _start_session(self):
        def make_event(nm):
            ev = lttng.Event()
            ev.name = nm
            ev.type = lttng.EVENT_TRACEPOINT
            ev.loglevel = lttng.EVENT_LOGLEVEL_ALL
            return ev

        events = (make_event(nm=name) for name in self.trace_events)
        r = lttng.create(name=self.sess_name, path=self.outdir)
        if r < 0:
            raise Exception("lttng.create({nm}) return code {code}".format(
                nm=self.sess_name, code=r))
        for ev in events:
            r = lttng.enable_event(handle=self.handle,
                                   event=ev,
                                   channel_name=None)
            if r < 0:
                raise Exception(
                    "lttng.enable_event({nm}) return code {code}".format(
                        nm=ev.name, code=r))
예제 #6
0
def lttng_start(events = ["*"], domain_type = lttng.DOMAIN_UST):
	if lttng.session_daemon_alive() == 0:
		daemon_cmd  = "lttng-sessiond --daemonize --quiet"
		daemon_cmd += " --pidfile " + sessiond_pidfile
		subprocess.check_call(daemon_cmd, shell=True)

	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))
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))
print("Tracing...")
time.sleep(2)
print("Stopped.")
ret = lttng.stop(ses_name)
if ret < 0:
    raise LTTngError(lttng.strerror(ret))

# Destroying tracing session
예제 #8
0
def lttng_session(session_name, command, names, analyzer):
    ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S-%f')
    tracedir = os.environ['HOME'] + "/lttng-traces/" + session_name + "-" + ts
    print('Writing trace to ' + tracedir)
    lttng.destroy(session_name)
    res = lttng.create(session_name, tracedir)
    if res<0:
        raise Exception("Failed to create lttng session")

    dom = lttng.Domain()
    dom.type = lttng.DOMAIN_UST

    han = None
    han = lttng.Handle(session_name, dom)
    if han is None:
        raise Exception("Handle not created")

    channel = lttng.Channel()
    channel.name = "channel0"
    channel.attr.overwrite = 0
    channel.attr.subbuf_size = 1048576
    channel.attr.num_subbuf = 8
    channel.attr.switch_timer_interval = 0
    channel.attr.read_timer_interval = 0
    channel.attr.output = lttng.EVENT_MMAP

    res = lttng.enable_channel(han, channel)
    if res<0:
        raise Exception("Failed to enable channel")
    
    for n in names:
        # lttng enable-event -u 'memcached:*'
        event = lttng.Event()
        event.type = lttng.EVENT_TRACEPOINT
        event.name = n
        lttng.enable_event(han, event, "channel0")

    os.system("lttng add-context -s" + session_name + " -u -t perf:thread:cycles -t pthread_id")

#    ctx = lttng.EventContext()
#    ctx.type = EVENT_CONTEXT_PTHREAD_ID
#    res = lttng.add_context(han, ctx, None, None)
#    assert res >= 0  
#
#    ctx.type = EVENT_CONTEXT_PERF_COUNTER
#    ctx.u.perf_counter.name = "cpu-cycles"
#    res = lttng.add_context(han, ctx, None, None)
#    assert res >= 0  

    lttng.start(session_name)

    print("running ", command)
    os.system(command)

    lttng.stop(session_name)
    lttng.destroy(session_name)
    
    subdir = subprocess.check_output(['ls', tracedir+'/ust/pid/']).decode("utf-8").rstrip()

    babeldir = tracedir+'/ust/pid/'+subdir
    print("analyzing trace in", babeldir)

    col = babeltrace.TraceCollection()
    if col.add_trace(babeldir, 'ctf') is None:
        raise RuntimeError('Cannot add trace')
    return analyzer(col)
예제 #9
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))
print("Tracing...")
time.sleep(2)
print("Stopped.")
ret = lttng.stop(ses_name)
if ret < 0:
    raise LTTngError(lttng.strerror(ret))

예제 #10
0
    channel.attr.overwrite = 0
    channel.attr.subbuf_size = 4096
    channel.attr.num_subbuf = 8
    channel.attr.switch_timer_interval = 0
    channel.attr.read_timer_interval = 200
    channel.attr.output = lttng.EVENT_SPLICE

    event = lttng.Event()
    event.name = "sched_switch"
    event.type = lttng.EVENT_TRACEPOINT
    event.loglevel_type = lttng.EVENT_LOGLEVEL_ALL

    ret = lttng.create(sess_name, trace_dest)
    assert ret == 0

    han = None
    han = lttng.Handle(sess_name, dom)
    assert han != None

    lttng.enable_channel(han, channel)
    lttng.enable_event(han, event, channel.name)

    print(lttng.list_channels(han))

    lttng.start(sess_name)
    time.sleep(0.1)
    lttng.stop(sess_name)

    ret = lttng.destroy(sess_name)
    assert ret == 0