BSD 2-Clause "Simplified" License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:Google Orbit 性能分析器

项目背景与痛点

在涉及到复杂的C/C++应用开发过程中,性能成为了决定应用成败的关键因素之一。为了找到性能瓶颈,开发者往往需要借助性能分析工具。虽然市场上已有不少成熟的工具,但它们很少能满足全部需求,尤其是对于复杂的多线程应用。此时,Google Orbit 应运而生,提供了全面的数据收集与高效的数据展示,使开发者能够快速定位性能瓶颈,并进行优化。

Google Orbit 即时性能分析器主要针对C/C++应用,通过在运行时收集数据,为开发者提供了详尽的函数调用图、线程状态和性能指标。它利用现代CPU的性能监控功能,为每一帧捕获CPU事件,从而生成详细的数据,帮助开发者更好地理解和优化程序。

核心技术揭秘

Google Orbit 的核心是其数据采集和展示机制。通过插入内核模块或使用采样驱动捕获CPU事件,Orbit能够实时监控应用性能。它借助于现代CPU提供的性能监控接口,精准地捕捉每一帧的数据,然后通过高效的数据处理算法分析这些数据,产出易于理解的图表供开发者查看。

对Google Orbit的技术架构进行分解,可以看到多个组件各有其独特的角色,如下图所示:

graph TD subgraph "Orbit 架构" A[Daemon 进程] -->|"收集 CPU 事件"| B[监听器 (Listener)] B -->|"预处理数据"| C[数据处理器 (Data Processor)] C -->|"生成图表显示"| D{"图形显示 (Graph Display)"} D -->|"数据渲染"| E[客户端 (Client)] end D -->|"WebSocket 数据流"| E

通过上述架构图可以看出,Orbit的设计很大程度上依赖于高效的实时数据处理能力,通过WebSocket实时传输处理后的数据至客户端。这不仅避免了数据积压,还提升了用户体验。

功能亮点与差异

Google Orbit 与其他性能分析器相比,拥有明显的优点。尤其是以下几个方面:

  1. 实时性高:通过 WebSocket 在客户端显示数据,用户能够实时查看性能状况,迅速进行调整。
  2. 自解释功能:Orbit有直观的图形界面,能够解释函数调用关系,直观明了地展示各线程状态的变化。
  3. 灵活的数据采集:支持使用内核模块及采样驱动,可以自定义采集点和性能指标,采集方式灵活多样。

应用场景与落地建议

尽管 Google Orbit 功能强大,但并非适用于所有场景。特别需要注意的是:

  1. 兼容性问题:使用内核模块时可能会带来兼容性问题,开发时需注意系统版本和配置。
  2. 资源消耗:数据采集和处理可能会消耗较多系统资源,尤其是在资源受限的生产环境中需谨慎使用。

Orbit非常适合大型多线程应用的实时性能监控,尤其在游戏开发及高并发服务器优化方面,开发团队可以借助它快速定位线程间性能瓶颈,实现性能提升。

综合评价

Google Orbit 提供了全面的实时性能监控机制,满足了高性能应用开发的需求。尤其在分析复杂多线程应用时,它能够通过详尽的数据展示帮助开发者快速定位性能问题。但需要注意的是,由于其实时数据处理依赖,生产环境中的使用需谨慎,以免影响普通业务运行。总的来说,Orbit 是一款强大且灵活的C/C++性能分析工具,适于对性能有高要求的资深开发者使用。

关于

GitHub 原始描述(英文)

C/C++ Performance Profiler

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
9346
价值分
3128
活跃状态
归档

语言占比

C
C++
CMake
Jupyter Notebook
PowerShell
Python
Shell

README

ORBIT

builds and tests Debian package OpenSSF Scorecard

ORBIT Logo

This project is not maintained by Google engineers anymore at this point.

Orbit, the Open Runtime Binary Instrumentation Tool is a standalone native application profiler for Windows and Linux. It supports native applications written in languages such as C, C++, Rust, or Go. Its main purpose is to help developers identify the performance bottlenecks of a complex application. Orbit can be also used to visualize the execution flow of such applications.

The key differentiator with many existing tools is that no alteration to the target process is necessary. Orbit does not require you to change a single line of code. It doesn’t require you to recompile or even relaunch the application you want to profile. Everything is done seamlessly, right when you need it. It requires zero integration time and zero iteration time.

Orbit combines sampling and dynamic instrumentation to optimize the profiling workflow. Sampling can quickly identify interesting functions to instrument. Dynamic instrumentation results in exact function entry and exit information which is presented in the form of per-thread hierarchical call graphs. Manual instrumentation markers can be added to the source code and further allows for value-tracking. Scheduling events are also shown to visualize when a thread was running and on what core. Furthermore, Orbit visualizes thread dependencies, showing which thread got blocked or unblocked by which other thread. For AMD GPUs, the submission, scheduling and hardware execution timings of a job is visualized. Additional GPU data, such as Vulkan debug markers can be retrieved using Orbit’s Vulkan layer. Memory consumption and page-fault information is visualized as well.

An introduction to Orbit’s key features can be found in the following YouTube video: Orbit Presentation

Features

  • Dynamic Instrumentation (no code change required)
  • Callstack Sampling
  • Wine/Proton Mixed-Callstack Profiling
  • Thread Scheduling and Dependency Tracing
  • Memory Tracing
  • GPU Driver Tracepoints (AMD only)
  • Vulkan Debug Label and Command Buffer Tracing (AMD only)
  • Manual Instrumentation
  • Source Code and Disassembly View
  • Remote Profiling
  • Debug Symbol Parsing (ELF, DWARF, PE and PDB)
  • Full Serialization of Captured Data

Note

Orbit’s focus has shifted to the Linux version. Windows local profiling is currently only supported partially and major features, such as dynamic instrumentation, are not yet implemented. It is possible however to profile Linux executables from a Windows UI instance. For Windows local profiling, you can still use the released binaries, but please note that they are deprecated and mostly undocumented.

Build

Please have a look at the first three sections of our development documentation. It describes how to build Orbit and which compilers, platforms, and tools are supported and needed.

Workflow

Note An extensive documentation of the usage of Orbit can be found in our usage documentation.

The following describes the basic workflow of Orbit:

  1. Select a process in the list of currently running processes in the connection setup dialog, and click Start Session.
  2. The list of loaded modules will appear at the top of the Symbols tab.
  3. Orbit tries to automatically retrieve debug information of the modules. See here on how to load symbols for modules Orbit failed to load. For successfully loaded module symbols, the Functions tab will get populated.
  4. Select functions you wish to dynamically instrument in the Functions tab by Right-Click and choosing Hook.
  5. Start profiling by pressing F5. To stop profiling, press F5 again. You can either zoom time using W and S or Ctrl + the scroll wheel. You can also Ctrl+Right-Click and drag to zoom to a specific time range. To scale the UI, press Ctrl + +/-. Press SPACE to see the last 2 seconds of capture.
  6. You can select sections of the per-thread sampling event track to get a sampling report of your selection.

Presets

Once you have loaded the debug information for your modules and have chosen functions of interest to dynamically instrument, you can save your profiling preset so that you won’t have to do this manually again. To save a preset, go to File > Save Preset

Feedback

Questions and comments are more than welcome: please open an issue.

About

Orbit was created by Pierric Gimmig. It was further developed and maintained by a team of engineers at Google. As of now, the project is however not being maintained by Google engineers anymore.

The following people worked on Orbit:

License

License (BSD 2-clause)

OSI Approved License
Copyright (c) 2020 The Orbit Authors. All rights reserved.

BSD 2-Clause License

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

评论

暂无评论