예제 #1
0
파일: plugin_cpu.py 프로젝트: zdohnal/tuned
    def _check_arch(self):
        intel_archs = ["x86_64", "i686", "i585", "i486", "i386"]
        self._arch = platform.machine()

        if self._arch in intel_archs:
            # Possible other x86 vendors (from arch/x86/kernel/cpu/*):
            # "CentaurHauls", "CyrixInstead", "Geode by NSC", "HygonGenuine", "GenuineTMx86",
            # "TransmetaCPU", "UMC UMC UMC"
            cpu = procfs.cpuinfo()
            vendor = cpu.tags.get("vendor_id")
            if vendor is "GenuineIntel":
                self._is_intel = True
            elif vendor is "AuthenticAMD" or vendor is "HygonGenuine":
                self._is_amd = True
            else:
                # We always assign Intel, unless we know better
                self._is_intel = True
            log.info("We are running on an x86 %s platform" % vendor)
        else:
            log.info("We are running on %s (non x86)" % self._arch)

        if self._is_intel is True:
            # Check for x86_energy_perf_policy, ignore if not available / supported
            self._check_energy_perf_bias()
            # Check for intel_pstate
            self._check_intel_pstate()
예제 #2
0
파일: tuna-cmd.py 프로젝트: noushi/tuna
def get_nr_cpus():
	global nr_cpus
	if nr_cpus:
		return nr_cpus
	nr_cpus = procfs.cpuinfo().nr_cpus
	return nr_cpus
예제 #3
0
 def get_nr_cpus(self):
     if self.nr_cpus:
         return self.nr_cpus
     self.nr_cpus = procfs.cpuinfo().nr_cpus
     return self.nr_cpus
예제 #4
0
파일: procview.py 프로젝트: noushi/tuna
    def __init__(self, treeview, ps, show_kthreads, show_uthreads,
                 cpus_filtered, gladefile):
        self.ps = ps
        self.treeview = treeview
        self.nr_cpus = procfs.cpuinfo().nr_cpus
        self.gladefile = gladefile

        self.evlist = None
        try:
            self.perf_init()
        except:  # No perf, poll /proc baby, poll
            pass

        if not ps[1]["status"].has_key("voluntary_ctxt_switches"):
            self.nr_columns = 5
        else:
            self.nr_columns = 7
        try:
            if ps[1]["cgroups"]:
                self.nr_columns = self.nr_columns + 1
        except:
            pass

        self.columns = (gui.list_store_column(_("PID")),
                        gui.list_store_column(_("Policy"),
                                              gobject.TYPE_STRING),
                        gui.list_store_column(_("Priority")),
                        gui.list_store_column(_("Affinity"),
                                              gobject.TYPE_STRING))

        if self.nr_columns == 5:
            (self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF,
             self.COL_CMDLINE) = range(self.nr_columns)
            self.columns = self.columns + (gui.list_store_column(
                _("Command Line"), gobject.TYPE_STRING))

        elif self.nr_columns == 6:
            (self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF,
             self.COL_CGROUP, self.COL_CMDLINE) = range(self.nr_columns)
            self.columns = self.columns + (
                gui.list_store_column(_("CGroup"), gobject.TYPE_STRING),
                gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

        elif self.nr_columns == 7:
            (self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF,
             self.COL_VOLCTXT, self.NONVOLCTXT,
             self.COL_CMDLINE) = range(self.nr_columns)
            self.columns = self.columns + (
                gui.list_store_column(_("VolCtxtSwitch"), gobject.TYPE_UINT),
                gui.list_store_column(_("NonVolCtxtSwitch"),
                                      gobject.TYPE_UINT),
                gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

        elif self.nr_columns == 8:
            (self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF,
             self.COL_VOLCTXT, self.COL_NONVOLCTXT, self.COL_CGROUP,
             self.COL_CMDLINE) = range(self.nr_columns)
            self.columns = self.columns + (
                gui.list_store_column(_("VolCtxtSwitch"), gobject.TYPE_UINT),
                gui.list_store_column(_("NonVolCtxtSwitch"),
                                      gobject.TYPE_UINT),
                gui.list_store_column(_("CGroup"), gobject.TYPE_STRING),
                gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

        self.tree_store = gtk.TreeStore(
            *gui.generate_list_store_columns_with_attr(self.columns))
        self.treeview.set_model(self.tree_store)

        # Allow selecting multiple rows
        selection = treeview.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        # Allow enable drag and drop of rows
        self.treeview.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, gui.DND_TARGETS,
            gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE)
        self.treeview.connect("drag_data_get", self.on_drag_data_get_data)
        try:
            self.treeview.connect("query-tooltip", self.on_query_tooltip)
        except:
            # old versions of pygtk2+ doesn't have this signal
            pass

        self.renderer = gtk.CellRendererText()
        for col in range(self.nr_columns):
            column = gtk.TreeViewColumn(self.columns[col].name,
                                        self.renderer,
                                        text=col)
            column.add_attribute(self.renderer, "weight",
                                 col + self.nr_columns)
            column.set_sort_column_id(col)
            if (col == self.COL_CGROUP):
                column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
                column.set_fixed_width(130)
            try:
                self.treeview.set_tooltip_column(col)
            except:
                # old versions of pygtk2+ doesn't have this signal
                pass
            column.set_resizable(True)
            self.treeview.append_column(column)

        self.show_kthreads = show_kthreads
        self.show_uthreads = show_uthreads
        self.cpus_filtered = cpus_filtered
        self.refreshing = True
예제 #5
0
파일: tuna-cmd.py 프로젝트: noushi/tuna
def get_nr_cpus():
    global nr_cpus
    if nr_cpus:
        return nr_cpus
    nr_cpus = procfs.cpuinfo().nr_cpus
    return nr_cpus
예제 #6
0
파일: rtps.py 프로젝트: cz172638/ait
            voluntary_ctxt_switches = int(
                ps[pid]["status"]["voluntary_ctxt_switches"])
            nonvoluntary_ctxt_switches = int(
                ps[pid]["status"]["nonvoluntary_ctxt_switches"])
        except:
            voluntary_ctxt_switches = -1
            nonvoluntary_ctxt_switches = -1
        print "%5d %6s %5d %8s %9d %12s %15s %s" % (
            pid, sched, rtprio, thread_affinity, voluntary_ctxt_switches,
            nonvoluntary_ctxt_switches, cmd, users)


if __name__ == '__main__':

    ps = procfs.pidstats()
    cpuinfo = procfs.cpuinfo()
    irqs = procfs.interrupts()

    show_header()
    show(ps, cpuinfo, irqs)

    try:
        interval = int(sys.argv[1])
        while True:
            time.sleep(interval)
            ps.reload()

            show_header()
            show(ps, cpuinfo, irqs)
    except:
        pass
예제 #7
0
파일: rtps.py 프로젝트: acmel/ait
		try:
			voluntary_ctxt_switches = int(ps[pid]["status"]["voluntary_ctxt_switches"])
			nonvoluntary_ctxt_switches = int(ps[pid]["status"]["nonvoluntary_ctxt_switches"])
		except:
			voluntary_ctxt_switches = -1
			nonvoluntary_ctxt_switches = -1
		print "%5d %6s %5d %8s %9d %12s %15s %s" % (pid, sched, rtprio,
							    thread_affinity,
							    voluntary_ctxt_switches,
							    nonvoluntary_ctxt_switches,
							    cmd, users)

if __name__ == '__main__':

	ps = procfs.pidstats()
	cpuinfo = procfs.cpuinfo()
	irqs = procfs.interrupts()

	show_header()
	show(ps, cpuinfo, irqs)

	try:
		interval = int(sys.argv[1])
		while True:
			time.sleep(interval)
			ps.reload()

			show_header()
			show(ps, cpuinfo, irqs)
	except:
		pass
예제 #8
0
파일: procview.py 프로젝트: bristot/tuna
	def __init__(self, treeview, ps,
		     show_kthreads, show_uthreads,
		     cpus_filtered, gladefile):
		self.ps = ps
		self.treeview = treeview
		self.nr_cpus = procfs.cpuinfo().nr_cpus
		self.gladefile = gladefile
	
		self.evlist = None
		try:
			self.perf_init() 
		except: # No perf, poll /proc baby, poll
			pass

		if not ps[1]["status"].has_key("voluntary_ctxt_switches"):
			self.nr_columns = 5
		else:
			self.nr_columns = 7
		try:
			if ps[1]["cgroups"]:
				self.nr_columns = self.nr_columns + 1
		except:
			pass

		self.columns = (gui.list_store_column(_("PID")),
						gui.list_store_column(_("Policy"), gobject.TYPE_STRING),
						gui.list_store_column(_("Priority")),
						gui.list_store_column(_("Affinity"), gobject.TYPE_STRING))

		if self.nr_columns==5:
			( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CMDLINE ) = range(self.nr_columns)
			self.columns = self.columns + (gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

		elif self.nr_columns==6:
			( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CGROUP, self.COL_CMDLINE ) = range(self.nr_columns)
			self.columns = self.columns + (gui.list_store_column(_("CGroup"), gobject.TYPE_STRING),
										   gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

		elif self.nr_columns==7:
			( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_VOLCTXT,
				self.NONVOLCTXT, self.COL_CMDLINE ) = range(self.nr_columns)
			self.columns = self.columns + (gui.list_store_column(_("VolCtxtSwitch"), gobject.TYPE_UINT),
										   gui.list_store_column(_("NonVolCtxtSwitch"), gobject.TYPE_UINT),
										   gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

		elif self.nr_columns==8:
			( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_VOLCTXT,
				self.COL_NONVOLCTXT, self.COL_CGROUP, self.COL_CMDLINE ) = range(self.nr_columns)
			self.columns = self.columns + (gui.list_store_column(_("VolCtxtSwitch"), gobject.TYPE_UINT),
										   gui.list_store_column(_("NonVolCtxtSwitch"), gobject.TYPE_UINT),
										   gui.list_store_column(_("CGroup"), gobject.TYPE_STRING),
										   gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))

		self.tree_store = gtk.TreeStore(*gui.generate_list_store_columns_with_attr(self.columns))
		self.treeview.set_model(self.tree_store)

		# Allow selecting multiple rows
		selection = treeview.get_selection()
		selection.set_mode(gtk.SELECTION_MULTIPLE)

		# Allow enable drag and drop of rows
		self.treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
						       gui.DND_TARGETS,
						       gtk.gdk.ACTION_DEFAULT | gtk.gdk.ACTION_MOVE)
		self.treeview.connect("drag_data_get", self.on_drag_data_get_data)
		try:
			self.treeview.connect("query-tooltip", self.on_query_tooltip)
		except:
			# old versions of pygtk2+ doesn't have this signal
			pass

		self.renderer = gtk.CellRendererText()
		for col in range(self.nr_columns):
			column = gtk.TreeViewColumn(self.columns[col].name,
						    self.renderer, text = col)
			column.add_attribute(self.renderer, "weight",
					     col + self.nr_columns)
			column.set_sort_column_id(col)
			if(col == self.COL_CGROUP):
				column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
				column.set_fixed_width(130)
			try:
				self.treeview.set_tooltip_column(col)
			except:
				# old versions of pygtk2+ doesn't have this signal
				pass
			column.set_resizable(True)
			self.treeview.append_column(column)

		self.show_kthreads = show_kthreads
		self.show_uthreads = show_uthreads
		self.cpus_filtered = cpus_filtered
		self.refreshing = True
예제 #9
0
def read_inventory():
    # get the data from SMOLT but modify it for how RHTS expects to see it
    # Eventually we'll switch over to SMOLT properly.
    data = {}
    flags = []
    data['Devices'] = []

    procCpu  = procfs.cpuinfo()
    smoltCpu = smolt.read_cpuinfo()
    memory   = smolt.read_memory()
    profile  = smolt.Hardware()

    arch = smoltCpu['platform']

    if arch in ["i386", "x86_64"]:
        for cpuflag in procCpu.tags['flags'].split(" "):
            flags.append(cpuflag)
        cpu = dict(vendor     = smoltCpu['type'],
                   model      = int(procCpu.tags['model']),
                   modelName  = smoltCpu['model'],
                   speed      = float(procCpu.tags['cpu mhz']),
                   processors = int(procCpu.nr_cpus),
                   cores      = int(procCpu.nr_cores),
                   sockets    = int(procCpu.nr_sockets),
                   CpuFlags   = flags,
                   family     = int(smoltCpu['model_number']),
                   stepping   = int(procCpu.tags['stepping']),
                  )
    elif arch in ["ppc", "ppc64"]:
        cpu = dict(vendor     = "IBM",
                   model      = 0,
                   modelName  = str(procCpu.tags['cpu']),
                   speed      = float(re.findall('\d+.+\d+', procCpu.tags['clock'])[0]),
                   processors = int(procCpu.nr_cpus),
                   cores      = 0,
                   sockets    = 0,
                   CpuFlags   = flags,
                   family     = 0,
                   stepping   = 0,
                 )
    elif arch in ["s390", "s390x"]:
        for cpuflag in procCpu.tags['features'].split(" "):
            flags.append(cpuflag)
        proc = dict([tuple(s.strip() for s in kv.split('=')) for kv in procCpu.tags['processor 0'].split(',')])
        cpu = dict(vendor     = str(procCpu.tags['vendor_id']),
                   model      = 0,
                   modelName  = str(proc['machine']),
                   processors = int(procCpu.tags['# processors']),
                   cores      = 0,
                   sockets    = 0,
                   CpuFlags   = flags,
                   family     = 0,
                   speed      = 0,
                   stepping   = 0,
                  )
    elif arch == "ia64":
        for cpuflag in procCpu.tags['features'].split(","):
            flags.append(cpuflag.strip())
        cpu = dict(vendor     = smoltCpu['type'],
                   model      = int(procCpu.tags['model']),
                   modelName  = smoltCpu['model'],
                   speed      = float(procCpu.tags['cpu mhz']),
                   processors = int(procCpu.nr_cpus),
                   cores      = int(procCpu.nr_cores),
                   sockets    = int(procCpu.nr_sockets),
                   CpuFlags   = flags,
                   family     = int(smoltCpu['model_rev']),
                   stepping   = 0,
                  )

    data['Cpu'] = cpu
    data['Arch'] = [arch]
    data['vendor'] = "%s" % profile.host.systemVendor
    data['model'] = "%s" % profile.host.systemModel
    data['formfactor'] = "%s" % profile.host.formfactor
    data['memory'] = int(memory['ram'])

    disklist = []
    diskdata = {}
    disks = Disks()
    for disk in Disks():
        disklist.append(disk.to_dict())
    diskdata['Disks'] = disklist

    data['Disk'] = diskdata

    if hasattr(profile.host, 'numaNodes'):
        data['Numa'] = {'nodes': profile.host.numaNodes}
    else:
        data['Numa'] = {
            'nodes': len(glob.glob('/sys/devices/system/node/node*')), #: number of NUMA nodes in the system, or 0 if not supported
        }

    if os.path.exists('./hvm_detect'):
        hypervisor = Popen(['./hvm_detect'], stdout=PIPE).communicate()[0]
        hvm_map = {"No KVM or Xen HVM\n"    : None,
                   "KVM guest.\n"           : u'KVM',
                   "Xen HVM guest.\n"       : u'Xen',
                   "Microsoft Hv guest.\n"  : u'HyperV',
                   "VMWare guest.\n"        : u'VMWare',
                  }
        data['Hypervisor'] = hvm_map[hypervisor]

    for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
        device = dict ( vendorID = "%04x" % (VendorID and VendorID or 0),
                        deviceID = "%04x" % (DeviceID and DeviceID or 0),
                        subsysVendorID = "%04x" % (SubsysVendorID and SubsysVendorID or 0),
                        subsysDeviceID = "%04x" % (SubsysDeviceID and SubsysDeviceID or 0),
                        bus = str(Bus),
                        driver = str(Driver),
                        type = str(Type),
                        description = str(Description))
        data['Devices'].append(device)

    return data