使用 uftrace 分析C++程序后如何理解 2 个 main() 函数

How to understand 2 main() functions after using uftrace to profile the C++ program?

本文关键字:main 函数 何理解 分析 uftrace C++ 程序 使用      更新时间:2023-10-16

我正在尝试uftrace来分析以下简单的C++程序:

#include <iostream>
class A {
public:
        A() {std::cout << "A is created" << std::endl;}
        ~A() {std::cout << "A is destroyed" << std::endl;}
};
int main() {
        A a;
        return 0;
}

配置文件结果如下所示:

# uftrace a.out
A is created
A is destroyed
# DURATION    TID     FUNCTION
   2.026 us [ 4828] | __cxa_atexit();
            [ 4828] | main() {
            [ 4828] |   __static_initialization_and_destruction_0() {
  89.397 us [ 4828] |     std::ios_base::Init::Init();
   0.768 us [ 4828] |     __cxa_atexit();
  93.029 us [ 4828] |   } /* __static_initialization_and_destruction_0 */
  94.425 us [ 4828] | } /* main */
            [ 4828] | main() {
            [ 4828] |   A::A() {
  11.104 us [ 4828] |     std::operator <<();
  10.825 us [ 4828] |     std::basic_ostream::operator <<();
  24.514 us [ 4828] |   } /* A::A */
            [ 4828] |   A::~A() {
   0.978 us [ 4828] |     std::operator <<();
   1.676 us [ 4828] |     std::basic_ostream::operator <<();
   4.819 us [ 4828] |   } /* A::~A */
  31.428 us [ 4828] | } /* main */
   2.095 us [ 4828] | std::ios_base::Init::~Init();

让我感到困惑的是有2 main()功能。从跟踪中,我想它们与iostream初始化有关,但即使如此,我认为每个可执行文件应该只有1 main()条目。如何解读?

uftrace用于删除符号demangler中的一些前缀,但它可能会使某些用户感到困惑,所以我提交了一个补丁来保留它,现在它被合并了 -https://github.com/namhyung/uftrace/pull/87

因此,如果您将uftrace更新到当前主节点。 您将看到第一个main()现在_GLOBAL__sub_I_main()

感谢您的反馈!