Luca Canali on 26 May 2016

Topic: In this post you will find a short discussion and pointers to the code of a few sample scripts that I have written using Linux BPF/bcc and uprobes for Oracle tracing.

Previous work and motivations

Tools for dynamic tracing are very useful for troubleshooting and internals investigations of Oracle workloads. Dynamic tracing probes on the OS/kernel, can be used to measure the details for I/O latency for example. Moreover probes on the Oracle userspace functions can be be used to complement Oracle instrumentation and probe deeper into the internals of the Oracle engine, when needed. For example in a work done in collaboration with Frits Hoogland(link is external) we have investigated how to link Oracle wait event interface with tools able to probe the userspace, such as gdb and dynamic tracing tools as DTrace, SystemTap and Perf. More details and examples on this topic can be found in previous work: Modern Linux Tools for Oracle Troubleshooting (presentation at UKOUG Tech14)Life of an Oracle I/O: Tracing Logical and Physical I/O with SystemTap(link is external)Linux Perf Probes for Oracle Tracing(link is external)Flame Graphs for Oracle(link is external).

What's new with BPF/bcc

BPF together with his frontend bcc(link is external) are new and exciting technologies in the Linux dynamic tracing ecosystem. If you are not familiar with them, you can get up to speed using the excellent material in Brendan Gregg's blog(link is external). While the tools are still in development as I write this, a large amount of important features are already available starting from kernel 4.5, notably the support for uprobes that I have used in the scripts discussed later in this post.

I have started experimenting with porting a few probes for the Oracle userspace that I had written using SystemTap and discussed in this blog. While the language/syntax is completely different between SystemTap and BPF/bcc, porting the probes has turned out to be relatively straightforward. The work has been made substantially easier by the availability of a large selection of well-written and documented scripts in the tools directory of bcc(link is external). At present writing BPF/bcc scripts is a mixture of coding in Python and C, which feels to me both familiar and at the same time strangely low-level compared to the more mature environments for example of DTrace and SystemTap.

The example scripts that I have written using BPF/bcc are on Github(link is external). Here is a list with comments:

Script name

Short description

ora_sqlparse_trace.py(link is external)

Tracing of Oracle SQL parsing. This script traces SQL hard parsing on Oracle binaries hooking on the Oracle function "opiprs" and reads from function arguments (CPU registers) and from process memory.

ora_wait_trace.py(link is external)

Tracing of Oracle wait events. This script traces Oracle sessions by hooking on the functions "kskthewt" and "kews_update_wait_time" and reads from function arguments (CPU registers).

ora_logicalIO_histogram.py(link is external)

Logical IO latency histograms. This script measures the latency between call and return time for the Oracle function "kcbgtcr", which is an important part of the logical IO processing for consistent reads.

ora_wait_histogram.py(link is external)

Wait event latency histograms. This script traces Oracle sessions by hooking on the functions "kskthewt" and "kews_update_wait_time" and reads from function arguments (CPU registers). BPF computes the latency histogram for the wait events and the script prints the values on stdout.

An example of the usage of ora_wait_histogram.py to measure and display wait event latency:

# stdbuf -oL ./ora_wait_histogram.py 10 10|sed -e 's/event# = /event#=/g' -f eventsname.sed

Start tracing oracle wait events... Hit Ctrl-C to end.

event=db file sequential read

wait time, microsec : count     distribution

0 -> 1          : 0        |                                        |

2 -> 3          : 0        |                                        |

4 -> 7          : 0        |                                        |

8 -> 15         : 0        |                                        |

16 -> 31         : 0        |                                        |

32 -> 63         : 0        |                                        |

64 -> 127        : 25       |                                        |

128 -> 255        : 24521    |********************                    |

256 -> 511        : 46788    |****************************************|

512 -> 1023       : 12169    |**********                              |

1024 -> 2047       : 1132     |                                        |

2048 -> 4095       : 660      |                                        |

4096 -> 8191       : 248      |                                        |

8192 -> 16383      : 29       |                                        |

Latency heat maps to display histograms collected with BPF/bcc

PyLatencyMap (link is external)is a command-line tool for visualizing latency histograms using heat maps on terminal graphics, using ANSI escape codes. PyLatencyMap can be used to investigate I/O performance for random I/O, especially suited for the cases of multiple modes of response time from the storage (SSD cache, HDD, latency outliers). The original idea for PyLatencyMap comes from the work of Brendan Gregg(link is external) on latency heat maps. I have added to the PyLatencyMap repository(link is external) a modified version of the biolatency.py(link is external) script to measure I/O latency histograms: this is the link to the script pylatencymap_biolatency.py(link is external) and an example of heat maps generated with PyLatencyMap with the script Example11_BPF-bcc_blockIO_latency.sh(link is external):

The test workload has been generated using Kevin Closson's SLOB(link is external). Additional references with a more detailed discussion of the topic of testing Oracle I/O with SLOB and measuring latency heat maps are:

Heat Map Visualization of I/O Latency with SystemTap and PyLatencyMap(link is external) and OraLatencyMap v1.1 and Testing I/O with SLOB 2(link is external).

Notes on the test environment

The scripts discussed in this post have been developed on Fedora 24 (alpha) running Linux kernel version 4.6 (using the rawhide kernel) and have been tested on workloads generated using Oracle version 11.2.0.4. This is not an Oracle-supported configuration and  the scripts are intended mainly as a demonstration of the technology and for learning purposes.

Here are some pointers on the steps I used to setup a lab environment for testing:

Note in particular the step for configuring the rawhide kernel, probably a good choice when testing BPF, as new features are being added on a regular basis as I write this:
# sudo dnf update
 
Additional pointers and recipes on how to install Oracle 11.2 on Fedora can be found on Tim Hall(link is external)'s website at: https://oracle-base.com/articles/11g/articles-11g(link is external)
 
 

Conclusions

BPF with its bcc frontend are new and powerful tools for dynamic tracing for Linux. A discussion of the merits and shortfalls of BPF/bcc vs other existing solutions in the Linux dynamic tracing ecosystem is beyond the scope of this post. What you can find in this post are a few example scripts that I have written for tracing Oracle using BPF/bcc anduprobes and an additional script for integrating BPF/bcc with PyLatencyMap, which provides visualization as heat maps of the histograms generated using BPF/bcc.

Although the BPF/bcc environment is currently under evolution, it appears already a very useful addition to the toolbox for troubleshooting and performance investigations of Linux workloads. A set of example scripts/tools that come with the bcc repository are of great help for getting started both with using BPF/bcc and with writing new scripts. BPF/bcc can only run on relatively new kernels (as I write this, I have tested the scripts discussed in this post on kernel version 4.6) and this is an obstacle for its adoption in many environments, at least in the short term.

Credits and acknowledgements

Many of the original ideas and tools discussed here are inspired or directly derived from the awesome published work of Brendan Gregg(link is external).

Many thanks also to the development teams of BPF and bcc(link is external) for providing and supporting this new powerful tools. In particular thanks to Brenden Blanco(link is external) for his work on uprobes for bcc and for his support on issue #478(link is external).

The work of investigating Oracle userspace with dynamic tracing tools has been done in collaboration with Frits Hoogland(link is external).

最新文章

  1. 创建ejs模板的express工程
  2. 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分的解决办法方案
  3. 【推荐】【给中高级开发者】构建高性能ASP.NET应用的几点建议
  4. [FPGA] 2、新建并运行一个工程
  5. 开源面向对象数据库 db4o 之旅,第 1 部分: 初识 db4o
  6. redis配置认证密码
  7. Bootstrap3.0学习第九轮(CSS补充)
  8. Selenium firefox 版本问题
  9. 高性能 Socket 组件 HP-Socket v3.2.1-RC2 公布
  10. redis8--数据持久化两种方式
  11. 机器学习 - pycharm, pyspark, spark集成篇
  12. js 数据加载loading封装
  13. Javabean介绍
  14. 设置build.gradle打包时自动加时间
  15. autolayout后获取frame
  16. MySQL使用索引的场景分析、不能使用索引的场景分析
  17. MySQL优化:explain using temporary
  18. mysql配置和管理(转载)
  19. 左连接sql
  20. 【搜索】POJ-2718 全排列+暴力

热门文章

  1. Hadoop4.2HDFS测试报告之二
  2. #2 create and populate a database && realistic and practical applications
  3. python基础学习笔记——类的成员
  4. python面试题解析(数据库和缓存)
  5. jquery获得iframe内容的高度
  6. 安装python包
  7. 为什么要使用数据库连接池?以及用法(DBUtils)
  8. Android Webview 与JS交互
  9. 【bzoj2339】[HNOI2011]卡农 dp+容斥原理
  10. 【bzoj3166】[Heoi2013]Alo 可持久化Trie树+STL-set