使用 uftrace 分析C++程序后如何理解 2 个 main() 函数
How to understand 2 main() functions after using uftrace to profile the C++ program?
我正在尝试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()
。
感谢您的反馈!
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- "main"函数堆栈中的对象在第一个任务运行时被覆盖 (FreeRTOS)
- 为什么 'main' 函数中的局部 int 变量会自动初始化?
- 为什么在我的 main 函数中声明整数后我的整数数组中会出现错误?
- 尝试更改 main 函数内的全局变量值时出现编译错误 C++.
- 我应该在 main 函数中写什么来测试我的问题?
- 如何在 main 函数中输出两个新字符串C++?
- 有没有办法通过 main 函数访问受保护的矢量大小而无需将其转换为公共?
- 我们可以在main函数中声明嵌套类对象吗
- 为什么Main函数上的Sleep()会停止所有线程
- C++ main 函数中初始化静态变量
- 为什么VC++/MFC没有main函数?
- 如何在 main 函数的一个对象中初始化两个类的值?C++
- 在 C++ 中解析 main 函数的大量输入的正确方法是什么
- 如何编写一个 void 函数,该函数将在数组中搜索值,并通过引用将该值的位置传递回 main 函数
- 如何将矩阵参数发送到从C 中的MAIN函数
- 如何从子例程函数获取到 main 函数的返回值
- 为什么我不能在 main 函数中更改类的公共变量
- C++编译错误:多个定义"main",但项目中只有一个 main 函数
- 如何使用 x86 程序集在 c 中访问 main 函数中的变量