1.简介
堆栈推导一般用于coredump
文件分析,火焰图
制作等场景.
了解其原理,有助于帮助我们分析异常问题,以及优化火焰图的制作流程,减少不完整栈情况的出现.
堆栈推导有两种常见方式: fp
与dwarf
. 本篇文章介绍这2种堆栈推导方式的原理及适用场景.
2.示例代码
在本篇文章中,我们将使用以下示例代码进行说明:
#include <iostream>
#include <chrono>
#include <thread>
using namespace std::chrono_literals;
int func2(int f) {
int r = 120;
for (int i = 0; i < 10000; i++) {
r += (f*i);
std::this_thread::sleep_for(10ms);
}
return r;
}
int func1(int a) {
int b = a + 100;
int c = b + 200;
auto d = func2(c);
return d;
}
int main() {
int value = func1(100);
std::cout << "return " << std::endl;
return 0;
}