def __init__(self, monitor_repository, storage_factory, hardware_inventory, device_matcher, device_matcher_udev, plugin_instance_factory, global_cfg, variables): super(SchedulerPlugin, self).__init__(monitor_repository, storage_factory, hardware_inventory, device_matcher, device_matcher_udev, plugin_instance_factory, global_cfg, variables) self._has_dynamic_options = True self._daemon = consts.CFG_DEF_DAEMON self._sleep_interval = int(consts.CFG_DEF_SLEEP_INTERVAL) if global_cfg is not None: self._daemon = global_cfg.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON) self._sleep_interval = int( global_cfg.get(consts.CFG_SLEEP_INTERVAL, consts.CFG_DEF_SLEEP_INTERVAL)) self._cmd = commands() # default is to whitelist all and blacklist none self._ps_whitelist = ".*" self._ps_blacklist = "" self._cpus = perf.cpu_map() self._scheduler_storage_key = self._storage_key( command_name="scheduler") self._irq_storage_key = self._storage_key(command_name="irq") try: self._scheduler_utils = SchedulerUtils() except AttributeError: self._scheduler_utils = SchedulerUtilsSchedutils()
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(): 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
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)
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)
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))
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
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)
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 = {}
def _isolated_cores(self, enabling, value, verify, ignore_missing): # currently unsupported if verify: return None # TODO merge with instance._cpus cpus = list(perf.cpu_map()) if enabling: if value is not None: affinity = self._cmd.cpulist_invert(value) sa = set(affinity) if set(cpus).intersection(sa) != sa: log.error("invalid isolated_cores specified, '%s' don't match available cores '%s'" % (value, ",".cpus)) return None self._set_ps_affinity(affinity, True) else: self._set_ps_affinity(cpus, False)
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
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 = {}
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
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
def __init__(self, *args, **kwargs): super(IrqbalancePlugin, self).__init__(*args, **kwargs) self._cpus = perf.cpu_map()