Rate This Document
Findability
Accuracy
Completeness
Readability

Example

This section demonstrates how to collect data during runtime, analyze and display a function call sequence diagram, and analyze the POSIX function compatibility.

Example

  1. The source file is test_posix.c. Compile the source file to generate the binary file test_posix.
    1
    gcc /home/demo/test_posix.c -o /home/demo/test_posix -pthread
    
  2. Collect POSIX function call and parameter information of the binary file. Assume that the configuration file is /home/demo/config.txt and the binary file is test_posix.
    • Collecting data in dynamic library mode
      1
      2
      cd /home/demo/
      LD_PRELOAD=./librecord.so RECORD_CONF=config.txt RECORD_OUT_DIR=/home/demo/data/ ./test_posix
      

      The librecord.so, libglib-2.0.so, and libgobject-2.0.so files are stored in /home/demo/.

    • Collecting data in Attach mode
      1
      devkit advisor knet attach -p 623456 -i /home/demo/config.txt -o /home/demo/data/
      

      623456 is the PID.

    One or more data files are generated in the /home/demo/data/ path.

  3. View the generated data files.
    1
    ls /home/demo/data/
    

    Command output:

    1
    record.3649201  record.3649202  record.3649259  record.3649260  record.3649261  record.3649262  record.3649263  record.3649264  record.3649265  record.3649266
    

    Ten data files are generated in the /home/demo/data/ path.

  4. View a data file.
    1
    vim /home/demo/data/record.3649201
    

    Content of the record.3649201 data file

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    1 36702160 3649201 3649201 3649201 3649201 3111602
    0 fork 36625210 36910470 285260 3649202 0
    0 socket 1037031630 1037053970 22340 4 3 2 1 0
    0 connect 1037099200 1037167150 67950 0 3 4 P1{sin_family:2,sin_port:33315,sin_addr:{s_addr:16777343}} 16 16777343 39623
    0 getsockname 1037304820 1037306380 1560 0 3 4 P1{sin_family:2,sin_port:39623,sin_addr:{s_addr:16777343}} P1{16}
    0 getpeername 1037384790 1037385880 1090 0 3 4 P1{sin_family:2,sin_port:33315,sin_addr:{s_addr:16777343}} P1{16}
    0 fcntl 1037458160 1037460140 1980 2 3 4 3 0
    0 fcntl 1037465900 1037467060 1160 0 3 4 4 2050
    0 pthread_create 1037481550 1037544030 62480 0 4 P1 P0 P1 P1
    0 pthread_create 1037551390 1037579390 28000 0 4 P1 P0 P1 P1
    0 pthread_create 1037585300 1037668480 83180 0 4 P1 P0 P1 P1
    0 pthread_create 1037675450 1037702300 26850 0 4 P1 P0 P1 P1
    3 18073
    
  5. Display the sequence diagram and network data. Assume that the data file path is /home/demo/data/.
    1
    devkit advisor knet seq-diag -d /home/demo/data -o /home/demo
    

    The knet-analysis_Timestamp.tar.gz package is generated in the /home/demo path. Download the package to the local PC and decompress it. After the decompression is complete, open the folder and run the knet-analysis.exe file. Then the network data overview and detailed sequence diagram are displayed. When a message cluster contains too much information, a heat map is used to display the overall message distribution. Click the heat map to drill down to the sequence diagram, so as to improve information identification.

  6. Display the compatibility information. Assume that the compatibility configuration file is /home/demo/compat_conf.json.
    1
    devkit advisor knet compat -d /home/demo/data -c /home/demo/compat_conf.json
    

    Command output:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    =====ERROR: some function calls do not satisfy conditions======
    [Function call] socket 2 1 0
    [Condition] Operation Not Allowed: Socket creation in child processes is forbidden. (PID: 3649202)
    
    [Function call] fcntl 4 3 0
    [Condition] arg 2 should only have these flags: 2048
    
    [Function call] fcntl 4 4 2050
    [Condition] arg 2 should only have these flags: 2048
    
    [Function call] fcntl 4 3 0
    [Condition] arg 2 should only have these flags: 2048
    
    [Function call] fcntl 4 4 2050
    [Condition] arg 2 should only have these flags: 2048
    
    [Function call] send 4 P1 11 0
    [Condition] arg 3 should only have these flags: 64
    ...
    ===============================================================
    K-NET tools executed successfully.
    

    The command output shows the incompatible functions: socket(), fcntl(), and send().