性能测试
一、时间戳转化
#1--时间戳转化为日期
import datetime,time
timestamp = 163642240800
# 转换成localtime
time_local = time.localtime(timestamp / 1000)
# 转换成新的时间格式(精确到秒)
dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
print(dt) #2021-11-09 09:46:48
d = datetime.datetime.fromtimestamp(timestamp / 1000)
# 精确到毫秒
str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")
print(str1) #2021-11-09 09:46:48.000000
#2-日期转化为时间戳
# 字符类型的时间
tss1 = '2021-06-03 21:19:03'
# 转为时间数组
timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S")
print(timeArray)
# timeArray可以调用tm_year等
print(timeArray.tm_year)
print(timeArray.tm_yday)
# 转为时间戳
timeStamp = int(time.mktime(timeArray))
print(timeStamp)
二、获取系统信息
1.物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id)
2.cpu核数:单块CPU上面能处理数据的芯片组的数量,如双核、四核等 (cpu cores)
3.逻辑cpu数:一般情况下,逻辑cpu=物理CPU个数×每颗核数,如果不相等的话,则表示服务器的CPU支持超线程技术(HT:简单来说,它可使处理器中的1 颗内核如2 颗内核那样在操作系统中发挥作用。这样一来,操作系统可使用的执行资源扩大了一倍,大幅提高了系统的整体性能,此时逻辑cpu=物理CPU个数×每颗核数x2)
"""
查看CPU型号
"""
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
8 Intel(R) Xeon(R) CPU E5-2609 v2 @ 2.50GHz
"""
查看物理CPU个数
"""
# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
2
"""
查看CPU核心数
"""
# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores : 32
"""
查看cpu逻辑核数
"""
# cat /proc/cpuinfo | grep "processor" | wc -l
128
"""
查看服务器型号
"""
# grep 'DMI' /var/log/dmesg
DMI: Dell Inc. PowerEdge R720/******, BIOS 2.4.3 07/09/2014
"""
查看是32位还是64位系统
"""
# uname -a
Linux **** 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
"""
查看RAM
"""
# cat /proc/meminfo
MemTotal: 32826948 kB
MemFree: 30190792 kB
Buffers: 161544 kB
Cached: 1476004 kB
SwapCached: 0 kB
Active: 1377540 kB
Inactive: 814108 kB
Active(anon): 554320 kB
Inactive(anon): 20080 kB
Active(file): 823220 kB
Inactive(file): 794028 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 16482300 kB
SwapFree: 16482300 kB
Dirty: 5112 kB
Writeback: 0 kB
AnonPages: 553972 kB
Mapped: 129264 kB
Shmem: 20308 kB
Slab: 185168 kB
SReclaimable: 103320 kB
SUnreclaim: 81848 kB
KernelStack: 7968 kB
PageTables: 19384 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 32895772 kB
Committed_AS: 2453404 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 339064 kB
VmallocChunk: 34342499988 kB
HardwareCorrupted: 0 kB
AnonHugePages: 280576 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 5056 kB
DirectMap2M: 2045952 kB
DirectMap1G: 31457280 kB
"""
查看ROM
"""
# cat /proc/partitions
major minor #blocks name
7 0 2168646 loop0
7 1 3824640 loop1
8 0 975699968 sda
8 1 512000 sda1
8 2 975186944 sda2
253 0 52428800 dm-0
253 1 16482304 dm-1
253 2 906272768 dm-2