美文网首页
系统调用开销测试

系统调用开销测试

作者: yanfeizhang | 来源:发表于2020-05-24 17:58 被阅读0次
    #include <fcntl.h>  
    #include <stdio.h> 
    #include <stdlib.h> 
    
    int main()  
    {   
        char    c;  
        int     in;
        int     i;
    
        in = open("in.txt", O_RDONLY);  
        for(i=0; i<1000000; i++){
            read(in,&c,1);
        }
        return 0;  
    }
    
    #dd if=/dev/zero of=in.txt bs=1M count=1
    #gcc main.c -o main  
    #time ./main  
    real    0m0.258s   
    user    0m0.030s  
    sys     0m0.227s 
    
    # gcc main.c -o main  
    # perf stat ./main  
    
     Performance counter stats for './main':
    
            251.508810 task-clock                #    0.997 CPUs utilized
                     1 context-switches          #    0.000 M/sec
                     1 CPU-migrations            #    0.000 M/sec
                    97 page-faults               #    0.000 M/sec
           600,644,444 cycles                    #    2.388 GHz                     [83.38%]
           122,000,095 stalled-cycles-frontend   #   20.31% frontend cycles idle    [83.33%]
            45,707,976 stalled-cycles-backend    #    7.61% backend  cycles idle    [66.66%]
         1,008,492,870 instructions              #    1.68  insns per cycle
                                                 #    0.12  stalled cycles per insn [83.33%]
           177,244,889 branches                  #  704.726 M/sec                   [83.32%]
                 7,583 branch-misses             #    0.00% of all branches         [83.33%]
    
    $ vmstat 1
    procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
     r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
     1  0      0 1231716 339244 55474204    0    0     6   496    0    0  7  3 90  0  0  
     2  0      0 1231352 339244 55474204    0    0     0   128 57402 24593  5  2 92  0  0  
     2  0      0 1230988 339244 55474528    0    0     0   140 55267 24213  5  2 93  0  0  
     2  0      0 1230988 339244 55474528    0    0     0   332 56328 23672  5  2 93  0  0
    
    # strace -c php main.php  
    % time     seconds  usecs/call     calls    errors syscall  
    ------ ----------- ----------- --------- --------- ----------------  
     97.24    0.039698           1     30003           poll  
      2.20    0.000899           0     10003           sendto  
      0.30    0.000122           0     10000           recvfrom  
      0.13    0.000053           0     10069           gettimeofday  
      0.03    0.000013           2         6           socket  
      0.03    0.000012           0       408           munmap  
      0.02    0.000008           0       657           read
    
    # grep ctxt /proc/14862/status  
    voluntary_ctxt_switches:        4  
    nonvoluntary_ctxt_switches:     43  
    
    # grep ctxt /proc/14862/status  
    voluntary_ctxt_switches:        10005  
    nonvoluntary_ctxt_switches:     49
    
    # php main.php
    
    # cat /proc/softirqs  
                    CPU0       CPU1       CPU2       CPU3  
          HI:          0          0          0          0  
       TIMER:  196173081  145428444  154228333  163317242  
      NET_TX:          0          0          0          0  
      NET_RX:  178159928     116073      10108     160712  
    
    
    # cat /proc/softirqs  
                    CPU0       CPU1       CPU2       CPU3  
          HI:          0          0          0          0  
       TIMER:  196173688  145428634  154228610  163317624  
      NET_TX:          0          0          0          0  
      NET_RX:  178170212     116073      10108     160712
    
    -------------------------------------------------------------------------
    Host                 OS  2p/0K 2p/16K 2p/64K 8p/16K 8p/64K 16p/16K 16p/64K  
                             ctxsw  ctxsw  ctxsw ctxsw  ctxsw   ctxsw   ctxsw  
    --------- ------------- ------ ------ ------ ------ ------ ------- -------  
    bjzw_46_7 Linux 2.6.32- 2.7800 2.7800 2.7000 4.3800 4.0400 4.75000 5.48000
    

    相关文章

      网友评论

          本文标题:系统调用开销测试

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