mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 08:18:56 +02:00
Merge pull request #7436 from jherico/alloc_watch
Add a tracker and logging of memory allocated by the GPU library
This commit is contained in:
commit
fc920c321b
2 changed files with 65 additions and 1 deletions
2
cmake/externals/oglplus/CMakeLists.txt
vendored
2
cmake/externals/oglplus/CMakeLists.txt
vendored
|
@ -4,7 +4,7 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
${EXTERNAL_NAME}
|
${EXTERNAL_NAME}
|
||||||
URL http://iweb.dl.sourceforge.net/project/oglplus/oglplus-0.63.x/oglplus-0.63.0.zip
|
URL http://hifi-public.s3.amazonaws.com/dependencies/oglplus-0.63.0.zip
|
||||||
URL_MD5 de984ab245b185b45c87415c0e052135
|
URL_MD5 de984ab245b185b45c87415c0e052135
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
BUILD_COMMAND ""
|
BUILD_COMMAND ""
|
||||||
|
|
|
@ -10,11 +10,74 @@
|
||||||
//
|
//
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
#include <NumericalConstants.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace gpu;
|
using namespace gpu;
|
||||||
|
|
||||||
|
class AllocationDebugger {
|
||||||
|
public:
|
||||||
|
void operator+=(size_t size) {
|
||||||
|
_allocatedMemory += size;
|
||||||
|
maybeReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator-=(size_t size) {
|
||||||
|
_allocatedMemory -= size;
|
||||||
|
maybeReport();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString formatSize(size_t size) {
|
||||||
|
float num = size;
|
||||||
|
QStringList list;
|
||||||
|
list << "KB" << "MB" << "GB" << "TB";
|
||||||
|
|
||||||
|
QStringListIterator i(list);
|
||||||
|
QString unit("bytes");
|
||||||
|
|
||||||
|
while (num >= K && i.hasNext()) {
|
||||||
|
unit = i.next();
|
||||||
|
num /= K;
|
||||||
|
}
|
||||||
|
return QString().setNum(num, 'f', 2) + " " + unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void maybeReport() {
|
||||||
|
auto now = usecTimestampNow();
|
||||||
|
if (now - _lastReportTime < MAX_REPORT_FREQUENCY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t current = _allocatedMemory;
|
||||||
|
size_t last = _lastReportedMemory;
|
||||||
|
size_t delta = (current > last) ? (current - last) : (last - current);
|
||||||
|
if (delta > MIN_REPORT_DELTA) {
|
||||||
|
_lastReportTime = now;
|
||||||
|
_lastReportedMemory = current;
|
||||||
|
qDebug() << "Total allocation " << formatSize(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::atomic<size_t> _allocatedMemory;
|
||||||
|
std::atomic<size_t> _lastReportedMemory;
|
||||||
|
std::atomic<uint64_t> _lastReportTime;
|
||||||
|
|
||||||
|
static const float K;
|
||||||
|
// Report changes of 5 megabytes
|
||||||
|
static const size_t MIN_REPORT_DELTA = 1024 * 1024 * 5;
|
||||||
|
// Report changes no more frequently than every 15 seconds
|
||||||
|
static const uint64_t MAX_REPORT_FREQUENCY = USECS_PER_SECOND * 15;
|
||||||
|
};
|
||||||
|
|
||||||
|
const float AllocationDebugger::K = 1024.0f;
|
||||||
|
|
||||||
|
static AllocationDebugger allocationDebugger;
|
||||||
|
|
||||||
Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size) {
|
Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size) {
|
||||||
|
allocationDebugger += size;
|
||||||
if ( !dataAllocated ) {
|
if ( !dataAllocated ) {
|
||||||
qWarning() << "Buffer::Sysmem::allocateMemory() : Must have a valid dataAllocated pointer.";
|
qWarning() << "Buffer::Sysmem::allocateMemory() : Must have a valid dataAllocated pointer.";
|
||||||
return NOT_ALLOCATED;
|
return NOT_ALLOCATED;
|
||||||
|
@ -38,6 +101,7 @@ Resource::Size Resource::Sysmem::allocateMemory(Byte** dataAllocated, Size size)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::Sysmem::deallocateMemory(Byte* dataAllocated, Size size) {
|
void Resource::Sysmem::deallocateMemory(Byte* dataAllocated, Size size) {
|
||||||
|
allocationDebugger -= size;
|
||||||
if (dataAllocated) {
|
if (dataAllocated) {
|
||||||
delete[] dataAllocated;
|
delete[] dataAllocated;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue