python处理百万数据cpu

python处理百万数据cpu,第1张

35GHzIntelCorei7。Python是一个高层次的结合了解释性、编译性、互动性和面向对象的脚本语言,python处理百万数据cpu为35GHzIntelCorei7,cpu主要由运算器、控制器、寄存器三部分组成,从字面意思看就是运算就是起着运算的作用。

psutil是一个Python写的方便获取系统硬件和性能信息的库。它实现了同等命令行工具提供的功能,如ps、top、lsof、netstat、ifconfig、who、df、kill、free、nice、ionice、iostat、iotop、uptime、pidof、tty、taskset、pmap等。

>>>import psutil

>>>psutilcpu_count() #逻辑CPU个数

>>>psutilcpu_count(logical=False) #物理CPU个数

>>>psutilcpu_percent() #cpu平均使用率

>>>psutilcpu_percent(3) #最近3秒钟cpu平均使用率

>>>psutilcpu_freq() #CPU频率

scpufreq(current=8040, min=00, max=21120)

>>>psutilcpu_stats() #CPU状态

scpustats(ctx_switches=1910389985, interrupts=2644388135, soft_interrupts=0, syscalls=3686421224)

>>>import psutil

>>>psutilvirtual_memory()

部分嵌入式系统:

svmem(total=16919429120, available=4207607808, percent=751, used=12711821312, free=4207607808)

linux系统:

svmem(total=135077658624,available=12628275200,percent=907,used=122103193600,free=10256912384,active=111388827648,inactive=6278348800,buffers=278413312,cached=2439139328,shared=184320)

解析

1)total:总物理内存,包括已使用的物理内存和没使用的物理内存

total = used + free

2)used:已使用的物理内存

3)free:没使用的物理内存

4)available:可用内存,其包括没使用的物理内存,缓冲(如存在),缓存(若存在)。

available = free + buffers + cached

注意available和free的区别

5)percent:内存使用率,(总物理内存大小 - 可用内存大小) / 总物理内存大小 100

percent = (total - available) / total 100

延伸

交换内存

>>>import psutil

>>>psutilswap_memory()

sswap(total=29810581504, used=26177650688, free=3632930816, percent=878, sin=0, sout=0)

>>>import psutil

>>>psutildisk_usage("C:") # C盘的使用率

sdiskusage(total=285441257472, used=103434944512, free=182006312960, percent=362)

>>>psutildisk_usage("/") # 根分区的使用率

sdiskusage(total=225328492544, used=77228355584, free=148100136960, percent=343)

>>>psutildisk_partitions() # 获取分区信息

[sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed', maxfile=255, maxpath=260), sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed', maxf

ile=255, maxpath=260)]

>>>psutildisk_io_counters() #  获取硬盘总的io和读写信息

sdiskio(read_count=3036624, write_count=7461516, read_bytes=111278890496, write_bytes=176975582208, read_time=1369, write_time=3012)

>>>psutildisk_io_counters(perdisk=True) # 获取单分区的io和读写信息

{'PhysicalDrive0': sdiskio(read_count=3046900, write_count=7464803, read_bytes=111679064576, write_bytes=177050010624, read_time=1372, write_time=3014)}

你好:

你可以使用dir()获取wmi的函数信息;

import wmi 

import os 

import sys 

import platform 

import time 

 

def sys_version():  

    c = wmiWMI () 

    #获取 *** 作系统版本 

    for sys in cWin32_OperatingSystem(): 

        print "Version:%s" % sysCaptionencode("UTF8"),"Vernum:%s" % sysBuildNumber 

        print  sysOSArchitectureencode("UTF8")#系统是32位还是64位的 

        print sysNumberOfProcesses #当前系统运行的进程总数

 

def cpu_mem(): 

    c = wmiWMI ()        

    #CPU类型和内存 

    for processor in cWin32_Processor(): 

        #print "Processor ID: %s" % processorDeviceID 

        print "Process Name: %s" % processorNamestrip() 

    for Memory in cWin32_PhysicalMemory(): 

        print "Memory Capacity: %fMB" %(int(MemoryCapacity)/1048576) 

 

def cpu_use(): 

    #5s取一次CPU的使用率 

    c = wmiWMI() 

    while True: 

        for cpu in cWin32_Processor(): 

            timestamp = timestrftime('%a, %d %b %Y %H:%M:%S', timelocaltime()) 

            print '%s | Utilization: %s: %d %%' % (timestamp, cpuDeviceID, cpuLoadPercentage) 

            timesleep(5)    

              

def disk(): 

    c = wmiWMI ()    

    #获取硬盘分区 

    for physical_disk in cWin32_DiskDrive (): 

        for partition in physical_diskassociators ("Win32_DiskDriveToDiskPartition"): 

            for logical_disk in partitionassociators ("Win32_LogicalDiskToPartition"): 

                print physical_diskCaptionencode("UTF8"), partitionCaptionencode("UTF8"), logical_diskCaption 

    

    #获取硬盘使用百分情况 

    for disk in cWin32_LogicalDisk (DriveType=3): 

        print diskCaption, "%02f%% free" % (1000  long (diskFreeSpace) / long (diskSize)) 

 

def network(): 

    c = wmiWMI ()    

    #获取MAC和IP地址 

    for interface in cWin32_NetworkAdapterConfiguration (IPEnabled=1): 

        print "MAC: %s" % interfaceMACAddress 

    for ip_address in interfaceIPAddress: 

        print "ip_add: %s" % ip_address 

    print 

    

    #获取自启动程序的位置 

    for s in cWin32_StartupCommand (): 

        print "[%s] %s <%s>" % (sLocationencode("UTF8"), sCaptionencode("UTF8"), sCommandencode("UTF8"))  

    

    

    #获取当前运行的进程 

    for process in cWin32_Process (): 

        print processProcessId, processName 

 

def main(): 

    sys_version() 

    #cpu_mem() 

    #disk() 

    #network() 

    #cpu_use() 

 

if __name__ == '__main__': 

    main() 

    print platformsystem() 

    print platformrelease() 

    print platformversion() 

    print platformplatform() 

    print platformmachine()

以上就是关于python处理百万数据cpu全部的内容,包括:python处理百万数据cpu、psutil之cpu、memory、disk解析、python获取windows信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/10149074.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存