Esempio n. 1
0
def main():
	cpus = perf.cpu_map()
	threads = perf.thread_map()
	evsel = perf.evsel(type	  = perf.TYPE_SOFTWARE,
			   config = perf.COUNT_SW_DUMMY,
			   task = 1, comm = 1, mmap = 0, freq = 0,
			   wakeup_events = 1, watermark = 1,
			   sample_id_all = 1,
			   sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)

	"""What we want are just the PERF_RECORD_ lifetime events for threads,
	 using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1
	 (the default), makes perf reenable irq_vectors:local_timer_entry, when
	 disabling nohz, not good for some use cases where all we want is to get
	 threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY,
	 freq=0) instead."""

	evsel.open(cpus = cpus, threads = threads);
	evlist = perf.evlist(cpus, threads)
	evlist.add(evsel)
	evlist.mmap()
	while True:
		evlist.poll(timeout = -1)
		for cpu in cpus:
			event = evlist.read_on_cpu(cpu)
			if not event:
				continue
			print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
								event.sample_pid,
								event.sample_tid),
			print event
Esempio n. 2
0
def main():
    sys.stdout = open('/dev/stdout', 'wb')

    tp = tracepoint("devlink", "devlink_hwmsg")
    cpus = perf.cpu_map()
    threads = perf.thread_map(-1)

    evlist = perf.evlist(cpus, threads)
    evlist.add(tp)
    evlist.open()
    evlist.mmap()

    pcap_header_out(sys.stdout)

    while True:
        try:
            evlist.poll(timeout=-1)
        except KeyboardInterrupt:
            break
        for cpu in cpus:
            while True:
                event = evlist.read_on_cpu(cpu)
                if not event:
                    break
                if not isinstance(event, perf.sample_event):
                    continue
                event_out(event)
Esempio n. 3
0
def main(context_switch=0, thread=-1):
    cpus = perf.cpu_map()
    threads = perf.thread_map(thread)
    evsel = perf.evsel(type=perf.TYPE_SOFTWARE,
                       config=perf.COUNT_SW_DUMMY,
                       task=1,
                       comm=1,
                       mmap=0,
                       freq=0,
                       wakeup_events=1,
                       watermark=1,
                       sample_id_all=1,
                       context_switch=context_switch,
                       sample_type=perf.SAMPLE_PERIOD | perf.SAMPLE_TID
                       | perf.SAMPLE_CPU)
    """What we want are just the PERF_RECORD_ lifetime events for threads,
	 using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1
	 (the default), makes perf reenable irq_vectors:local_timer_entry, when
	 disabling nohz, not good for some use cases where all we want is to get
	 threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY,
	 freq=0) instead."""

    evsel.open(cpus=cpus, threads=threads)
    evlist = perf.evlist(cpus, threads)
    evlist.add(evsel)
    evlist.mmap()
    while True:
        evlist.poll(timeout=-1)
        for cpu in cpus:
            event = evlist.read_on_cpu(cpu)
            if not event:
                continue
            print "cpu: %2d, pid: %4d, tid: %4d" % (
                event.sample_cpu, event.sample_pid, event.sample_tid),
            print event
def main():
    tp = tracepoint("sched", "sched_switch")
    cpus = perf.cpu_map()
    threads = perf.thread_map(-1)

    evlist = perf.evlist(cpus, threads)
    evlist.add(tp)
    evlist.open()
    evlist.mmap()

    while True:
        evlist.poll(timeout=-1)
        for cpu in cpus:
            event = evlist.read_on_cpu(cpu)
            if not event:
                continue

            if not isinstance(event, perf.sample_event):
                continue

            print(
                "time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d"
                % (event.sample_time, event.prev_comm, event.prev_pid,
                   event.prev_prio, event.prev_state, event.next_comm,
                   event.next_pid, event.next_prio))
Esempio n. 5
0
def main():
	cpus = perf.cpu_map()
	threads = perf.thread_map()
	evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
<<<<<<< HEAD
			   wakeup_events = 1, watermark = 1,
=======
<<<<<<< HEAD
			   wakeup_events = 1, watermark = 1,
=======
			   wakeup_events = 1, sample_period = 1,
>>>>>>> 58a75b6a81be54a8b491263ca1af243e9d8617b9
>>>>>>> ae1773bb70f3d7cf73324ce8fba787e01d8fa9f2
			   sample_id_all = 1,
			   sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU | perf.SAMPLE_TID)
	evsel.open(cpus = cpus, threads = threads);
	evlist = perf.evlist(cpus, threads)
	evlist.add(evsel)
	evlist.mmap()
	while True:
		evlist.poll(timeout = -1)
		for cpu in cpus:
			event = evlist.read_on_cpu(cpu)
			if not event:
				continue
			print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
								event.sample_pid,
								event.sample_tid),
			print event
Esempio n. 6
0
def main():
    tp = tracepoint("devlink", "devlink_hwmsg")
    cpus = perf.cpu_map()
    threads = perf.thread_map(-1)

    evlist = perf.evlist(cpus, threads)
    evlist.add(tp)
    evlist.open()
    evlist.mmap()
    
    pcap_header_out()

    while True:
        try:
            evlist.poll(timeout = -1)
        except KeyboardInterrupt:
            break
        for cpu in cpus:
            while True:
                event = evlist.read_on_cpu(cpu)
                if not event:
                    break
                if not isinstance(event, perf.sample_event):
                    continue
                event_out(event)
Esempio n. 7
0
def main():
    tp      = tracepoint("sched", "sched_switch")
    cpus    = perf.cpu_map()
    threads = perf.thread_map(-1)

    evlist = perf.evlist(cpus, threads)
    evlist.add(tp)
    evlist.open()
    evlist.mmap()

    while True:
        evlist.poll(timeout = -1)
        for cpu in cpus:
            event = evlist.read_on_cpu(cpu)
            if not event:
                continue

            if not isinstance(event, perf.sample_event):
                continue

            print "time %u prev_comm=%s prev_pid=%d prev_prio=%d prev_state=0x%x ==> next_comm=%s next_pid=%d next_prio=%d" % (
                   event.sample_time,
                   event.prev_comm,
                   event.prev_pid,
                   event.prev_prio,
                   event.prev_state,
                   event.next_comm,
                   event.next_pid,
                   event.next_prio)
Esempio n. 8
0
    def _instance_init(self, instance):
        instance._has_dynamic_tuning = False
        instance._has_static_tuning = True
        # this is hack, runtime_tuning should be covered by dynamic_tuning configuration
        # TODO: add per plugin dynamic tuning configuration and use dynamic_tuning configuration
        # instead of runtime_tuning
        instance._runtime_tuning = True

        # FIXME: do we want to do this here?
        # recover original values in case of crash
        self._scheduler_original = self._storage.get(
            self._scheduler_storage_key, {})
        if len(self._scheduler_original) > 0:
            log.info("recovering scheduling settings from previous run")
            self._restore_ps_affinity()
            self._scheduler_original = {}
            self._storage.unset(self._scheduler_storage_key)

        self._cgroups_original_affinity = dict()

        # calculated by isolated_cores setter
        self._affinity = None

        self._cgroup_affinity_initialized = False
        self._cgroup = None
        self._cgroups = collections.OrderedDict([
            (self._sanitize_cgroup_path(option[7:]),
             self._variables.expand(affinity))
            for option, affinity in instance.options.items()
            if option[:7] == "cgroup." and len(option) > 7
        ])

        instance._scheduler = instance.options

        for k in instance._scheduler:
            instance._scheduler[k] = self._variables.expand(
                instance._scheduler[k])
        if self._cmd.get_bool(instance._scheduler.get("runtime", 1)) == "0":
            instance._runtime_tuning = False
        instance._terminate = threading.Event()
        if self._daemon and instance._runtime_tuning:
            try:
                instance._threads = perf.thread_map()
                evsel = perf.evsel(type=perf.TYPE_SOFTWARE,
                                   config=perf.COUNT_SW_DUMMY,
                                   task=1,
                                   comm=1,
                                   mmap=0,
                                   freq=0,
                                   wakeup_events=1,
                                   watermark=1,
                                   sample_type=perf.SAMPLE_TID
                                   | perf.SAMPLE_CPU)
                evsel.open(cpus=self._cpus, threads=instance._threads)
                instance._evlist = perf.evlist(self._cpus, instance._threads)
                instance._evlist.add(evsel)
                instance._evlist.mmap()
            # no perf
            except:
                instance._runtime_tuning = False
Esempio n. 9
0
	def perf_init(self):
		self.cpu_map = perf.cpu_map()
		self.thread_map = perf.thread_map()
		self.evsel_cycles = perf.evsel(task = 1, comm = 1,
					       wakeup_events = 1,
					       watermark = 1,
					       sample_type = perf.SAMPLE_CPU |
							     perf.SAMPLE_TID)
		self.evsel_cycles.open(cpus = self.cpu_map, threads = self.thread_map);
		self.evlist = perf.evlist(self.cpu_map, self.thread_map)
		self.evlist.add(self.evsel_cycles)
		self.evlist.mmap()
		self.pollfd = self.evlist.get_pollfd()
		for f in self.pollfd:
			gobject.io_add_watch(f, gtk.gdk.INPUT_READ, self.perf_process_events)
		self.perf_counter = {}
Esempio n. 10
0
    def _instance_init(self, instance):
        instance._has_dynamic_tuning = False
        instance._has_static_tuning = True
        # this is hack, runtime_tuning should be covered by dynamic_tuning configuration
        # TODO: add per plugin dynamic tuning configuration and use dynamic_tuning configuration
        # instead of runtime_tuning
        instance._runtime_tuning = True

        # FIXME: do we want to do this here?
        # recover original values in case of crash
        instance._scheduler_original = self._storage.get(
            self._scheduler_storage_key(instance), {})
        if len(instance._scheduler_original) > 0:
            log.info("recovering scheduling settings from previous run")
            self._instance_unapply_static(instance)
            instance._scheduler_original = {}
            self._storage.unset(self._scheduler_storage_key(instance))

        instance._scheduler = instance.options
        for k in instance._scheduler:
            instance._scheduler[k] = self._variables.expand(
                instance._scheduler[k])
        if self._cmd.get_bool(instance._scheduler.get("runtime", 1)) == "0":
            instance._runtime_tuning = False
        instance._terminate = threading.Event()
        if self._daemon and instance._runtime_tuning:
            try:
                instance._cpus = perf.cpu_map()
                instance._threads = perf.thread_map()
                evsel = perf.evsel(type=perf.TYPE_SOFTWARE,
                                   config=perf.COUNT_SW_DUMMY,
                                   task=1,
                                   comm=1,
                                   mmap=0,
                                   freq=0,
                                   wakeup_events=1,
                                   watermark=1,
                                   sample_type=perf.SAMPLE_TID
                                   | perf.SAMPLE_CPU)
                evsel.open(cpus=instance._cpus, threads=instance._threads)
                instance._evlist = perf.evlist(instance._cpus,
                                               instance._threads)
                instance._evlist.add(evsel)
                instance._evlist.mmap()
            # no perf
            except:
                instance._runtime_tuning = False
Esempio n. 11
0
 def perf_init(self):
     self.cpu_map = perf.cpu_map()
     self.thread_map = perf.thread_map()
     self.evsel_cycles = perf.evsel(task=1,
                                    comm=1,
                                    wakeup_events=1,
                                    watermark=1,
                                    sample_type=perf.SAMPLE_CPU
                                    | perf.SAMPLE_TID)
     self.evsel_cycles.open(cpus=self.cpu_map, threads=self.thread_map)
     self.evlist = perf.evlist(self.cpu_map, self.thread_map)
     self.evlist.add(self.evsel_cycles)
     self.evlist.mmap()
     self.pollfd = self.evlist.get_pollfd()
     for f in self.pollfd:
         gobject.io_add_watch(f, gtk.gdk.INPUT_READ,
                              self.perf_process_events)
     self.perf_counter = {}
Esempio n. 12
0
def main():
	cpus = perf.cpu_map()
	threads = perf.thread_map()
	evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
			   wakeup_events = 1, watermark = 1,
			   sample_id_all = 1,
			   sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
	evsel.open(cpus = cpus, threads = threads);
	evlist = perf.evlist(cpus, threads)
	evlist.add(evsel)
	evlist.mmap()
	while True:
		evlist.poll(timeout = -1)
		for cpu in cpus:
			event = evlist.read_on_cpu(cpu)
			if not event:
				continue
			print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
								event.sample_pid,
								event.sample_tid),
			print event
Esempio n. 13
0
def main():
	cpus = perf.cpu_map()
	threads = perf.thread_map()
	evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
			   wakeup_events = 1, watermark = 1,
			   sample_id_all = 1,
			   sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
	evsel.open(cpus = cpus, threads = threads);
	evlist = perf.evlist(cpus, threads)
	evlist.add(evsel)
	evlist.mmap()
	while True:
		evlist.poll(timeout = -1)
		for cpu in cpus:
			event = evlist.read_on_cpu(cpu)
			if not event:
				continue
			print "cpu: %2d, pid: %4d, tid: %4d" % (event.sample_cpu,
								event.sample_pid,
								event.sample_tid),
			print event
Esempio n. 14
0
	def _instance_init(self, instance):
		instance._has_dynamic_tuning = False
		instance._has_static_tuning = True
		# this is hack, runtime_tuning should be covered by dynamic_tuning configuration
		# TODO: add per plugin dynamic tuning configuration and use dynamic_tuning configuration
		# instead of runtime_tuning
		instance._runtime_tuning = True

		# FIXME: do we want to do this here?
		# recover original values in case of crash
		instance._scheduler_original = self._storage.get(self._scheduler_storage_key(instance), {})
		if len(instance._scheduler_original) > 0:
			log.info("recovering scheduling settings from previous run")
			self._instance_unapply_static(instance)
			instance._scheduler_original = {}
			self._storage.unset(self._scheduler_storage_key(instance))

		instance._scheduler = instance.options
		for k in instance._scheduler:
			instance._scheduler[k] = self._variables.expand(instance._scheduler[k])
		if self._cmd.get_bool(instance._scheduler.get("runtime", 1)) == "0":
			instance._runtime_tuning = False
		instance._terminate = threading.Event()
		if self._daemon and instance._runtime_tuning:
			try:
				instance._cpus = perf.cpu_map()
				instance._threads = perf.thread_map()
				evsel = perf.evsel(type = perf.TYPE_SOFTWARE,
					config = perf.COUNT_SW_DUMMY,
					task = 1, comm = 1, mmap = 0, freq = 0,
					wakeup_events = 1, watermark = 1,
					sample_type = perf.SAMPLE_TID | perf.SAMPLE_CPU)
				evsel.open(cpus = instance._cpus, threads = instance._threads)
				instance._evlist = perf.evlist(instance._cpus, instance._threads)
				instance._evlist.add(evsel)
				instance._evlist.mmap()
			# no perf
			except:
				instance._runtime_tuning = False