2013-09-07 06:13:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-01-27 18:37:44 +03:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2013-09-07 06:13:37 +04:00
|
|
|
#include "GfxTexturesReporter.h"
|
2016-01-27 18:37:44 +03:00
|
|
|
#include "gfxPrefs.h"
|
2013-09-07 06:13:37 +04:00
|
|
|
|
2016-02-03 23:24:47 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-07 06:13:37 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter)
|
2013-12-08 10:09:10 +04:00
|
|
|
|
2016-01-27 00:03:37 +03:00
|
|
|
Atomic<size_t> GfxTexturesReporter::sAmount(0);
|
2016-02-11 00:03:32 +03:00
|
|
|
Atomic<size_t> GfxTexturesReporter::sPeakAmount(0);
|
2016-01-27 00:03:37 +03:00
|
|
|
Atomic<size_t> GfxTexturesReporter::sTileWasteAmount(0);
|
2013-09-07 06:13:37 +04:00
|
|
|
|
2016-01-27 18:37:44 +03:00
|
|
|
std::string
|
|
|
|
FormatBytes(size_t amount)
|
|
|
|
{
|
|
|
|
std::stringstream stream;
|
|
|
|
int depth = 0;
|
|
|
|
double val = amount;
|
|
|
|
while (val > 1024) {
|
|
|
|
val /= 1024;
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* unit;
|
|
|
|
switch(depth) {
|
|
|
|
case 0:
|
|
|
|
unit = "bytes";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
unit = "KB";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
unit = "MB";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
unit = "GB";
|
|
|
|
break;
|
2016-08-23 09:30:37 +03:00
|
|
|
default:
|
|
|
|
unit = "";
|
|
|
|
break;
|
2016-01-27 18:37:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
stream << val << " " << unit;
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2013-09-07 06:13:37 +04:00
|
|
|
/* static */ void
|
2016-01-27 00:03:37 +03:00
|
|
|
GfxTexturesReporter::UpdateAmount(MemoryUse action, size_t amount)
|
2013-09-07 06:13:37 +04:00
|
|
|
{
|
|
|
|
if (action == MemoryFreed) {
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(amount <= sAmount, "GFX: Current texture usage greater than update amount.");
|
2016-01-27 00:03:37 +03:00
|
|
|
sAmount -= amount;
|
2016-01-27 18:37:44 +03:00
|
|
|
|
|
|
|
if (gfxPrefs::GfxLoggingTextureUsageEnabled()) {
|
|
|
|
printf_stderr("Current texture usage: %s\n", FormatBytes(sAmount).c_str());
|
|
|
|
}
|
2013-09-07 06:13:37 +04:00
|
|
|
} else {
|
2016-01-27 00:03:37 +03:00
|
|
|
sAmount += amount;
|
2016-02-11 00:03:32 +03:00
|
|
|
if (sAmount > sPeakAmount) {
|
|
|
|
sPeakAmount.exchange(sAmount);
|
2016-01-27 18:37:44 +03:00
|
|
|
if (gfxPrefs::GfxLoggingPeakTextureUsageEnabled()) {
|
|
|
|
printf_stderr("Peak texture usage: %s\n", FormatBytes(sPeakAmount).c_str());
|
|
|
|
}
|
2016-02-11 00:03:32 +03:00
|
|
|
}
|
2013-09-07 06:13:37 +04:00
|
|
|
}
|
2016-02-03 23:24:47 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
CrashReporter::AnnotateTexturesSize(sAmount);
|
|
|
|
#endif
|
2013-09-07 06:13:37 +04:00
|
|
|
}
|