• BCC源码内容概览(1)


    接前一篇文章:BCC源码编译和安装

    本文参考官网中的Contents部分的介绍。

    BCC源码根目录的文件,其中一些是同时包含C和Python的单个文件,另一些是.c和.py的成对文件,还有一些是目录。

    跟踪(Tracing)

    examples目录下的文件:

    • examples/tracing/bitehist.py

    块I/O大小直方图

    bcc/examples/tracing/bitehist.txt文件内容如下:

    1. Demonstrations of bitehist.py, the Linux eBPF/bcc version.
    2. This prints a power-of-2 histogram to show the block I/O size distribution.
    3. A summary is printed after Ctrl-C is hit.
    4. # ./bitehist.py
    5. Tracing... Hit Ctrl-C to end.
    6. ^C
    7. kbytes : count distribution
    8. 0 -> 1 : 3 | |
    9. 2 -> 3 : 0 | |
    10. 4 -> 7 : 211 |********** |
    11. 8 -> 15 : 0 | |
    12. 16 -> 31 : 0 | |
    13. 32 -> 63 : 0 | |
    14. 64 -> 127 : 1 | |
    15. 128 -> 255 : 800 |**************************************|
    16. This output shows a bimodal distribution. The largest mod of 800 I/O were
    17. between 128 and 255 Kbytes in size, and another mode of 211 I/O were between
    18. 4 and 7 Kbytes in size.
    19. Understanding this distribution is useful for characterizing workloads and
    20. understanding performance. The existence of this distribution is not visible
    21. from averages alone.
    • examples/tracing/disksnoop.py

    跟踪块设备I/O延迟。

    bcc/examples/tracing/disksnoop_example.txt文件内容如下:

    1. Demonstrations of disksnoop.py, the Linux eBPF/bcc version.
    2. This traces block I/O, a prints a line to summarize each I/O completed:
    3. # ./disksnoop.py
    4. TIME(s) T BYTES LAT(ms)
    5. 16458043.435457 W 4096 2.73
    6. 16458043.435981 W 4096 3.24
    7. 16458043.436012 W 4096 3.13
    8. 16458043.437326 W 4096 4.44
    9. 16458044.126545 R 4096 42.82
    10. 16458044.129872 R 4096 3.24
    11. 16458044.130705 R 4096 0.73
    12. 16458044.142813 R 4096 12.01
    13. 16458044.147302 R 4096 4.33
    14. 16458044.148117 R 4096 0.71
    15. 16458044.148950 R 4096 0.70
    16. 16458044.164332 R 4096 15.29
    17. 16458044.168003 R 4096 3.58
    18. 16458044.171676 R 4096 3.59
    19. 16458044.172453 R 4096 0.72
    20. 16458044.173213 R 4096 0.71
    21. 16458044.173989 R 4096 0.72
    22. 16458044.174739 R 4096 0.70
    23. 16458044.190334 R 4096 15.52
    24. 16458044.196608 R 4096 6.17
    25. 16458044.203091 R 4096 6.35
    26. The output includes a basic timestamp (in seconds), the type of I/O (W == write,
    27. R == read, M == metadata), the size of the I/O in bytes, and the latency (or
    28. duration) of the I/O in milliseconds.
    29. The latency is measured from I/O request to the device, to the device
    30. completion. This excludes latency spent queued in the OS.
    31. Most of the I/O in this example were 0.7 and 4 milliseconds in duration. There
    32. was an outlier of 42.82 milliseconds, a read which followed many writes (the
    33. high latency may have been caused by the writes still being serviced on the
    34. storage device).
    • examples/hello_world.py

    为新进程打印“Hello, World!”。

    bcc/examples/hello_world.py文件内容如下:

    1. #!/usr/bin/python
    2. # Copyright (c) PLUMgrid, Inc.
    3. # Licensed under the Apache License, Version 2.0 (the "License")
    4. # run in project examples directory with:
    5. # sudo ./hello_world.py"
    6. # see trace_fields.py for a longer example
    7. from bcc import BPF
    8. # This may not work for 4.17 on x64, you need replace kprobe__sys_clone with kprobe____x64_sys_clone
    9. BPF(text='int kprobe__sys_clone(void *ctx) { bpf_trace_printk("Hello, World!\\n"); return 0; }').trace_print()
    • examples/tracing/mysqld_query.py

    使用USDT探测跟踪MySQL服务器查询。

    bcc/examples/tracing/mysqld_query.txt文件内容如下:

    1. # ./mysqld_query.py `pgrep -n mysqld`
    2. TIME(s) COMM PID QUERY
    3. 17450459.549910001 mysqld 18608 select @@version_comment limit 1
    4. 17450463.822668001 mysqld 18608 SELECT DATABASE()
    5. 17450463.824042998 mysqld 18608 show databases
    6. 17450463.824570000 mysqld 18608 show tables
    7. 17450465.602717999 mysqld 18608 SELECT COUNT(*) FROM words
    8. 17450479.944897000 mysqld 18608 SELECT * FROM words WHERE word REGEXP '^bre.*n$'

  • 相关阅读:
    P1807 最长路题解【Floyd】
    武汉新时标文化传媒有限公司如何让你的店铺日出万单?
    全球数字高程数据(DEM)详解,还有地形晕渲、等高线等干货
    C++中构造函数什么时候会被调用(从本质上理解)
    无人机航迹规划:七种智能优化算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划--提供MATLAB代码
    spring boot零配置
    宇视科技通过stm32叠加字符串
    每周AI新闻(2024年第9周)微软与Mistral AI达成合作 | 谷歌发11B基础世界模型 | 传苹果放弃电动汽车制造转向生成式AI
    如何从单体架构迁移到微服务架构:挑战和最佳实践
    Vue-cli前端工程配置
  • 原文地址:https://blog.csdn.net/phmatthaus/article/details/133130069