X-Profiler / xprofiler

🌀An addon for node.js, which supporting output performance log and real-time profiling through sampling.
Other
422 stars 57 forks source link

fix: output native stack if HAVE_EXECINFO_H defined #196

Closed hyj1991 closed 1 year ago

hyj1991 commented 1 year ago

背景

alpine 等环境下缺少 execinfo 库函数导致 --build-from-source 失败。

优化

本 PR 增加 HAVE_EXECINFO_H 宏:

#if defined(__linux__) && !defined(__GLIBC__) || defined(__UCLIBC__) || \
    defined(_AIX)
#define HAVE_EXECINFO_H 0
#else
#define HAVE_EXECINFO_H 1
#endif

且仅在 HAVE_EXECINFO_H 生效时诊断报告输出 Native stack,否则输出空:

#if HAVE_EXECINFO_H
#include <cxxabi.h>
#include <execinfo.h>
#endif

#if (HAVE_EXECINFO_H)
void PrintNativeStack(JSONWriter* writer) {
  // 此时获取 native stack 详细信息
}
#else
void PrintNativeStack(JSONWriter* writer) {
  writer->json_arraystart("nativeStacks");
  writer->json_arrayend();
}
#endif

验证

已在 alpine@3.16 上验证通过。

其它

Reference:

codecov[bot] commented 1 year ago

Codecov Report

Merging #196 (dd1ff19) into master (5c594a0) will not change coverage. The diff coverage is n/a.

@@            Coverage Diff            @@
##            master      #196   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          296       296           
=========================================
  Hits           296       296           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more