Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/gl/GfxTexturesReporter.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include <string>
8
#include <sstream>
9
#include "nsExceptionHandler.h"
10
#include "GfxTexturesReporter.h"
11
#include "gfxPrefs.h"
12
13
using namespace mozilla;
14
using namespace mozilla::gl;
15
16
NS_IMPL_ISUPPORTS(GfxTexturesReporter, nsIMemoryReporter)
17
18
Atomic<size_t> GfxTexturesReporter::sAmount(0);
19
Atomic<size_t> GfxTexturesReporter::sPeakAmount(0);
20
Atomic<size_t> GfxTexturesReporter::sTileWasteAmount(0);
21
22
std::string
23
FormatBytes(size_t amount)
24
0
{
25
0
    std::stringstream stream;
26
0
    int depth = 0;
27
0
    double val = amount;
28
0
    while (val > 1024) {
29
0
        val /= 1024;
30
0
        depth++;
31
0
    }
32
0
33
0
    const char* unit;
34
0
    switch(depth) {
35
0
      case 0:
36
0
      unit = "bytes";
37
0
      break;
38
0
      case 1:
39
0
      unit = "KB";
40
0
      break;
41
0
      case 2:
42
0
      unit = "MB";
43
0
      break;
44
0
      case 3:
45
0
      unit = "GB";
46
0
      break;
47
0
      default:
48
0
      unit = "";
49
0
      break;
50
0
  }
51
0
52
0
  stream << val << " " << unit;
53
0
  return stream.str();
54
0
}
55
56
/* static */ void
57
GfxTexturesReporter::UpdateAmount(MemoryUse action, size_t amount)
58
0
{
59
0
    if (action == MemoryFreed) {
60
0
        MOZ_RELEASE_ASSERT(amount <= sAmount, "GFX: Current texture usage greater than update amount.");
61
0
        sAmount -= amount;
62
0
63
0
        if (gfxPrefs::GfxLoggingTextureUsageEnabled()) {
64
0
            printf_stderr("Current texture usage: %s\n", FormatBytes(sAmount).c_str());
65
0
        }
66
0
    } else {
67
0
        sAmount += amount;
68
0
        if (sAmount > sPeakAmount) {
69
0
            sPeakAmount.exchange(sAmount);
70
0
            if (gfxPrefs::GfxLoggingPeakTextureUsageEnabled()) {
71
0
                printf_stderr("Peak texture usage: %s\n", FormatBytes(sPeakAmount).c_str());
72
0
            }
73
0
        }
74
0
    }
75
0
76
0
    CrashReporter::AnnotateTexturesSize(sAmount);
77
0
}