美文网首页
2020-04-01 Liunx测试

2020-04-01 Liunx测试

作者: 帝龙至尊 | 来源:发表于2020-04-01 15:26 被阅读0次

启动时间相关

1. systemd-analyze命令

# 开机启动时间
root@TangramBook:~# systemd-analyze 
Startup finished in 5.843s (firmware) + 52ms (loader) + 5.113s (kernel) + 8.231s (userspace) = 19.241s
graphical.target reached after 8.224s in userspace
# 服务启动时间
root@TangramBook:~# systemd-analyze blame 
  3.868s cic.service
          3.433s NetworkManager-wait-online.service
          ...... 省略部分 ......
           498ms plymouth-quit-wait.service
           498ms plymouth-quit.service
           296ms docker.service
             2ms sys-kernel-config.mount
             2ms setvtrgb.service
           822us docker.socket
# 系统启动和运行(正常运行时间)以来的持续时间
root@TangramBook:~# uptime -p
up 22 hours, 23 minutes
# 系统启动和运行(正常运行时间)以来的持续时间
root@TangramBook:~# uptime -s

2. uptime命令

#  1. uptime命令
root@TangramBook:~# uptime 
 15:03:48 up  2:35,  2 users,  load average: 0.38, 0.16, 0.20
# 2.查看/proc/uptime文件计算系统启动时间
root@TangramBook:~# cat /proc/uptime
9339.47 73723.60
#  ----运用系统工具date即可算出系统启动时间
root@TangramBook:~# date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
2020-04-01 12:28:20
#  3.查看/proc/uptime文件计算系统运行时间
root@TangramBook:~# cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}'
系统已运行:0天2时36分23秒

3. who 命令

who -b 查看最后一次系统启动的时间。
who -r 查看当前系统运行时间

#  上次启动时间
root@TangramBook:~# who -b
         系统引导 2020-04-01 20:28
#  当前运行时间
root@TangramBook:~# who -r
         运行级别 5 2020-04-01 20:29
#  历史启动时间
root@TangramBook:~# last reboot
wtmp begins Wed Apr  1 15:03:35 2020
#  最后一次启动时间
root@TangramBook:~# last reboot | head -1

4. 通过脚本实现(sysinfo)

sysinfo结构
  sysinfo结构保持了系统启动后的信息,主要包括启动到现在的时间,可用内存空间、共享内存空间、进程的数目等。man sysinfo得到结果如下所示

struct sysinfo {
                 long uptime;             /* Seconds since boot */
                 unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
                 unsigned long totalram;  /* Total usable main memory size */
                 unsigned long freeram;   /* Available memory size */
                 unsigned long sharedram; /* Amount of shared memory */
                 unsigned long bufferram; /* Memory used by buffers */
                 unsigned long totalswap; /* Total swap space size */
                 unsigned long freeswap;  /* swap space still available */
                unsigned short procs;    /* Number of current processes */
                char _f[22];             /* Pads structure to 64 bytes */
            };

获取系统启动时间
  通过sysinfo获取系统启动到现在的秒数,用当前时间减去这个秒数即系统的启动时间。程序如下所示:

  #include <stdio.h>
  #include <sys/sysinfo.h>
  #include <time.h>
  #include <errno.h>
  
  static int print_system_boot_time()
  {
     struct sysinfo info;
     time_t cur_time = 0;
     time_t boot_time = 0;
     struct tm *ptm = NULL;
     if (sysinfo(&info)) {
     fprintf(stderr, "Failed to get sysinfo, errno:%u, reason:%s\n",
         errno, strerror(errno));
     return -1;
     }
     time(&cur_time);
     if (cur_time > info.uptime) {
     boot_time = cur_time - info.uptime;
     }
     else {
     boot_time = info.uptime - cur_time;
     }
     ptm = gmtime(&boot_time);
     printf("System boot time: %d-%-d-%d %d:%d:%d\n", ptm->tm_year + 1900,
         ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
    return 0; 
 }
 
 int main()
 {
     if (print_system_boot_time() != 0) {
     return -1;
     }
     return 0;
 }
#  1.uptime命令
root@TangramBook:~# ./time 
System boot time: 2020-04-01 20:28:38

电池耗电检测

  1. upower(系统自带) >>> upower -i `upower -e | grep 'BAT'`
    Upower工具
  2. batstat工具 >>> git clone https://github.com/Juve45/batstat.git
# 耗电量
root@TangramBook:~# ./batstat 
耗电量.png
  1. 电源统计工具(系统自带) >>> sudo apt-get install gnome-power-manager
    电源统计-详情
    电源统计-历史

LTP–linux稳定性测试,性能测试和压力测试

LTP套件是由 Linux Test Project 所开发的一套系统测试套件。它基于系统资源的利用率统计开发了一个测试的组合,为系统提供足够的压力。
Linux Test Project
项目官网http://linux-test-project.github.io/
邮件通知地址填写https://lists.linux.it/listinfo/ltp
源码地址https://github.com/linux-test-project/ltp

# INSTALL lib
root@TangramBook:~# apt install automake    
root@TangramBook:~# apt install autoconf    
root@TangramBook:~# apt install m4    
root@TangramBook:~# apt install g++    

# INSTALL lib
root@TangramBook:~# tar xzf ltp-XXXXXXXX.tar.gz    # 解压源码
root@TangramBook:~# cd ltp    # 开机时间
root@TangramBook:~# ./configure    # 检查环境配置
root@TangramBook:~# make all    
root@TangramBook:~# make install    
root@TangramBook:~# cd /opt/ltp    # 移动到安装目录
root@TangramBook:~# ./runltp    # 开始运行

# RUN LTP
#  修改基础运行时间 默认为1*5min
export LTP_TIMEOUT_MUL=5 #  修改基础运行时间 5*5min
# RUN 方法一
root@TangramBook:~# cd /opt/ltp/runltp./runltp -p -l /tmp/resultlog.20200401 -d /tmp -o /tmp/ltpscreen.20200401 -t 24h
        -p:人为指定日志格式,保证日志为可读格式
        -l:记录测试日志的文件
        -d:指定临时存储目录,默认为/tmp
        -o:直接打印测试输出到/tmp/ltpscreen.20200401
        -t:指定测试的持续时间 不指定则大致需3h/轮
# RUN 方法二
root@TangramBook:~# cd /opt/ltp/runltp./runalltests.sh  

LTP Runing log (部分输出结果)

  1. ltpscreen
[BEGIN] 2020/3/9 18:30:31
root@TangramBook:/opt/ltp# ./runltp -p -l /opt/ltp/output/a-resultlog.20200309-12h -d /tmp -o /opt/ltp/output/a-ltpscreen.20200309-12h -t 12h
INFO: creating /opt/ltp/output directory
INFO: no command files were provided. Executing following runtest scenario files:
syscalls fs fs_perms_simple fsx dio io mm ipc sched math nptl pty containers fs_bind controllers filecaps cap_bounds fcntl-locktests connectors power_management_tests hugetlb commands hyperthreading can cpuhotplug net.ipv6_lib input cve crypto kernel_misc uevent 
Checking for required user/group ids
'nobody' user id and group found.
'bin' user id and group found.
'daemon' user id and group found.
Users group found.
Sys group found.
Required users/groups exist.
If some fields are empty or look unusual you may have an old version.
Compare to the current minimal requirements in Documentation/Changes.

/etc/lsb-release
/etc/os-release
uname:
/proc/cmdline

Gnu C                  gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang                 
Gnu make               4.1
util-linux             2.31.1
mount                  linux 2.31.1(libmount 2.31.1: selinux, btrfs, assert, debug)
modutils               24
e2fsprogs              1.44.1
Linux C Library        > libc.2.27
Dynamic linker (ldd)   2.27
Procps                 3.3.12
iproute2               iproute2-ss180129
iputils                1.9.4
/opt/ltp/ver_linux: 115: /opt/ltp/ver_linux: ethtool: not found
Kbd                    2.0.4
Sh-utils               8.28
.................
AppArmor enabled
SELinux mode: unknown
no big block device was specified on commandline.
Tests which require a big block device are disabled.
You can specify it with option -z
COMMAND:    /opt/ltp/bin/ltp-pan   -e -S  -t 12h -a 7672     -n 7672 -p -f /tmp/ltp-6UDDAv3reI/alltests -l /opt/ltp/output/a-resultlog.20200309-12h -o /opt/ltp/output/a-ltpscreen.20200309-12h -C /opt/ltp/output/LTP_RUN_ON-a-ltpscreen.20200309-12h.failed -T /opt/ltp/output/LTP_RUN_ON-a-ltpscreen.20200309-12h.tconf
LOG File: /opt/ltp/output/a-resultlog.20200309-12h
OUTPUT File: /opt/ltp/output/a-ltpscreen.20200309-12h
FAILED COMMAND File: /opt/ltp/output/LTP_RUN_ON-a-ltpscreen.20200309-12h.failed
TCONF COMMAND File: /opt/ltp/output/LTP_RUN_ON-a-ltpscreen.20200309-12h.tconf
Running tests.......
PAN will run for 43200 seconds
........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================........................................................................................................................................................................................................TEST : TRY TO WRITE ON A READ  LOCK:====================================================================================================TEST : TRY TO WRITE ON A WRITE LOCK:====================================================================================================TEST : TRY TO READ  ON A READ  LOCK:====================================================================================================TEST : TRY TO READ  ON A WRITE LOCK:====================================================================================================TEST : TRY TO SET A READ  LOCK ON A READ  LOCK:====================================================================================================TEST : TRY TO SET A WRITE LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A WRITE LOCK ON A READ  LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO SET A READ  LOCK ON A WRITE LOCK:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTEST : TRY TO READ LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================TEST : TRY TO WRITE LOCK THE WHOLE FILE BYTE BY BYTE:====================================================================================================INFO: ltp-pan reported some tests FAIL
LTP Version: 20200120

       ###############################################################

            Done executing testcases.
            LTP Version:  20200120
       ###############################################################
  1. ltpscreen
#  resultlog
Test Start Time: Mon Mar  9 18:30:08 2020
-----------------------------------------
Testcase                                           Result     Exit Value
--------                                           ------     ----------
abort01                                            PASS       0    
accept01                                           PASS       0   
...省略部分...                                     ......      ...... 
msgstress02                                        PASS       0    
msgstress03                                        FAIL       6    

-----------------------------------------------
Total Tests: 2061
Total Skipped Tests: 206
Total Failures: 62
Kernel Version: Linux-4.19.0-generic
Machine Architecture: x86_64
Hostname: Ubuntu

相关文章

网友评论

      本文标题:2020-04-01 Liunx测试

      本文链接:https://www.haomeiwen.com/subject/syuouhtx.html