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
|
||||
m_ProgramStarted = -1;
|
||||
#endif //COLLECT_STATIC_VAR_DATA
|
||||
|
||||
#ifdef USE_CPPTRACE
|
||||
cpptrace::absorb_trace_exceptions(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
FILE* openFile(const char* fileName, bool append) {
|
||||
@ -105,6 +109,7 @@ class MemPlumberInternal {
|
||||
public:
|
||||
|
||||
bool isStarted() const { return m_Started; }
|
||||
FILE* dumper() const { return m_Dumper; }
|
||||
|
||||
static MemPlumberInternal& getInstance() {
|
||||
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
|
||||
const char* getCaller() {
|
||||
|
||||
if (!MemPlumberInternal::getInstance().isStarted())
|
||||
return "";
|
||||
|
||||
#ifdef USE_CPPTRACE
|
||||
const auto objTrace = cpptrace::generate_object_trace(/*skip=*/3, /*max_depth=*/1);
|
||||
const auto trace = objTrace.resolve();
|
||||
const auto line = trace.to_string();
|
||||
if (!line.empty()) {
|
||||
return line.c_str();
|
||||
static bool isDumping = false;
|
||||
auto dumper = MemPlumberInternal::getInstance().dumper();
|
||||
if (dumper && !isDumping) {
|
||||
isDumping = true;
|
||||
|
||||
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
|
||||
|
||||
|
@ -15,7 +15,7 @@ const char *const LOG_FILE_PATH = "memplumber.txt";
|
||||
|
||||
void MemPlumberUtil::start()
|
||||
{
|
||||
MemPlumber::start();
|
||||
MemPlumber::start(/*verbose=*/true, LOG_FILE_PATH, /*append=*/true);
|
||||
}
|
||||
|
||||
void MemPlumberUtil::stop()
|
||||
@ -25,12 +25,13 @@ void MemPlumberUtil::stop()
|
||||
|
||||
void MemPlumberUtil::checkAndStop()
|
||||
{
|
||||
stop();
|
||||
|
||||
QTimer::singleShot(10, [&] {
|
||||
size_t memLeakCount;
|
||||
uint64_t memLeakSize;
|
||||
MemPlumber::memLeakCheck(memLeakCount, memLeakSize, /*verbose=*/true, LOG_FILE_PATH);
|
||||
|
||||
stop();
|
||||
MemPlumber::memLeakCheck(
|
||||
memLeakCount, memLeakSize, /*verbose=*/true, LOG_FILE_PATH, /*append=*/true);
|
||||
|
||||
qCInfo(LC) << "Number of leaked objects:" << memLeakCount
|
||||
<< "Total amount of memory leaked:" << memLeakSize;
|
||||
|
Loading…
Reference in New Issue
Block a user