mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:05:12 +00:00
UI: MemPlumber: Print stack traces
This commit is contained in:
parent
4c6ea29491
commit
d03ec2027e
24
src/3rdparty/memplumber/memplumber.cpp
vendored
24
src/3rdparty/memplumber/memplumber.cpp
vendored
@ -63,6 +63,10 @@ class MemPlumberInternal {
|
|||||||
#else
|
#else
|
||||||
m_ProgramStarted = -1;
|
m_ProgramStarted = -1;
|
||||||
#endif //COLLECT_STATIC_VAR_DATA
|
#endif //COLLECT_STATIC_VAR_DATA
|
||||||
|
|
||||||
|
#ifdef USE_CPPTRACE
|
||||||
|
cpptrace::absorb_trace_exceptions(false);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* openFile(const char* fileName, bool append) {
|
FILE* openFile(const char* fileName, bool append) {
|
||||||
@ -105,6 +109,7 @@ class MemPlumberInternal {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
bool isStarted() const { return m_Started; }
|
bool isStarted() const { return m_Started; }
|
||||||
|
FILE* dumper() const { return m_Dumper; }
|
||||||
|
|
||||||
static MemPlumberInternal& getInstance() {
|
static MemPlumberInternal& getInstance() {
|
||||||
static MemPlumberInternal instance;
|
static MemPlumberInternal instance;
|
||||||
@ -362,15 +367,18 @@ class MemPlumberInternal {
|
|||||||
// We can use dbghelp but it's not supported on MinGW. Need to figure out a way to solve it on all platforms
|
// We can use dbghelp but it's not supported on MinGW. Need to figure out a way to solve it on all platforms
|
||||||
const char* getCaller() {
|
const char* getCaller() {
|
||||||
|
|
||||||
if (!MemPlumberInternal::getInstance().isStarted())
|
|
||||||
return "";
|
|
||||||
|
|
||||||
#ifdef USE_CPPTRACE
|
#ifdef USE_CPPTRACE
|
||||||
const auto objTrace = cpptrace::generate_object_trace(/*skip=*/3, /*max_depth=*/1);
|
static bool isDumping = false;
|
||||||
const auto trace = objTrace.resolve();
|
auto dumper = MemPlumberInternal::getInstance().dumper();
|
||||||
const auto line = trace.to_string();
|
if (dumper && !isDumping) {
|
||||||
if (!line.empty()) {
|
isDumping = true;
|
||||||
return line.c_str();
|
|
||||||
|
const auto objTrace = cpptrace::generate_object_trace(/*skip=*/1, /*max_depth=*/9);
|
||||||
|
const auto trace = objTrace.resolve();
|
||||||
|
|
||||||
|
fprintf(dumper, "Trace: %s\n", trace.to_string().c_str());
|
||||||
|
|
||||||
|
isDumping = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ const char *const LOG_FILE_PATH = "memplumber.txt";
|
|||||||
|
|
||||||
void MemPlumberUtil::start()
|
void MemPlumberUtil::start()
|
||||||
{
|
{
|
||||||
MemPlumber::start();
|
MemPlumber::start(/*verbose=*/true, LOG_FILE_PATH, /*append=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemPlumberUtil::stop()
|
void MemPlumberUtil::stop()
|
||||||
@ -25,12 +25,13 @@ void MemPlumberUtil::stop()
|
|||||||
|
|
||||||
void MemPlumberUtil::checkAndStop()
|
void MemPlumberUtil::checkAndStop()
|
||||||
{
|
{
|
||||||
|
stop();
|
||||||
|
|
||||||
QTimer::singleShot(10, [&] {
|
QTimer::singleShot(10, [&] {
|
||||||
size_t memLeakCount;
|
size_t memLeakCount;
|
||||||
uint64_t memLeakSize;
|
uint64_t memLeakSize;
|
||||||
MemPlumber::memLeakCheck(memLeakCount, memLeakSize, /*verbose=*/true, LOG_FILE_PATH);
|
MemPlumber::memLeakCheck(
|
||||||
|
memLeakCount, memLeakSize, /*verbose=*/true, LOG_FILE_PATH, /*append=*/true);
|
||||||
stop();
|
|
||||||
|
|
||||||
qCInfo(LC) << "Number of leaked objects:" << memLeakCount
|
qCInfo(LC) << "Number of leaked objects:" << memLeakCount
|
||||||
<< "Total amount of memory leaked:" << memLeakSize;
|
<< "Total amount of memory leaked:" << memLeakSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user