2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-09-07 06:13:37 +04:00
|
|
|
/* 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>
|
2017-10-10 16:11:07 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2013-09-07 06:13:37 +04:00
|
|
|
#include "GfxTexturesReporter.h"
|
2019-05-26 17:30:14 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
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
|
|
|
|
2019-06-15 02:42:59 +03:00
|
|
|
static std::string FormatBytes(size_t amount) {
|
2016-01-27 18:37:44 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void 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
|
|
|
|
2019-07-22 05:10:14 +03:00
|
|
|
if (StaticPrefs::gfx_logging_texture_usage_enabled_AtStartup()) {
|
2016-01-27 18:37:44 +03:00
|
|
|
printf_stderr("Current texture usage: %s\n",
|
|
|
|
FormatBytes(sAmount).c_str());
|
2013-09-07 06:13:37 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03: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);
|
2019-07-22 05:10:14 +03:00
|
|
|
if (StaticPrefs::gfx_logging_peak_texture_usage_enabled_AtStartup()) {
|
2016-01-27 18:37:44 +03:00
|
|
|
printf_stderr("Peak texture usage: %s\n",
|
|
|
|
FormatBytes(sPeakAmount).c_str());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 23:24:47 +03:00
|
|
|
|
|
|
|
CrashReporter::AnnotateTexturesSize(sAmount);
|
2013-09-07 06:13:37 +04:00
|
|
|
}
|