ManaPlus
memorymanager.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2016-2017 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
24 
26 
27 #include "utils/gettext.h"
28 #include "utils/stringutils.h"
29 
30 PRAGMA48(GCC diagnostic push)
31 PRAGMA48(GCC diagnostic ignored "-Wshadow")
32 #include <SDL_video.h>
33 PRAGMA48(GCC diagnostic pop)
34 
35 #include "debug.h"
36 
38 
40 {
41 }
42 
43 
44 int MemoryManager::getSurfaceSize(const SDL_Surface *const surface)
45 {
46  if (surface == nullptr)
47  return 0;
48  return CAST_S32(sizeof(SDL_Surface)) +
49  CAST_S32(sizeof(SDL_PixelFormat)) +
50  // aproximation for sizeof(SDL_BlitMap)
51  28 +
52  // pixels
53  surface->w * surface->h * 4 +
54  // private_hdata aproximation
55  10;
56 }
57 
58 void MemoryManager::printMemory(const std::string &name,
59  const int level,
60  const int localSum,
61  const int childsSum)
62 {
63  std::string str(level, ' ');
64  if (childsSum > 0)
65  {
66  logger->log("%s%s: %d = %d + %d",
67  str.c_str(),
68  name.c_str(),
69  localSum + childsSum,
70  localSum,
71  childsSum);
72  }
73  else
74  {
75  logger->log("%s%s: %d",
76  str.c_str(),
77  name.c_str(),
78  localSum);
79  }
80 }
81 
82 void MemoryManager::printAllMemory(ChatTab *const tab A_DYECMD_UNUSED)
83 {
84  if (logger == nullptr)
85  return;
86 
87 #ifdef DYECMD
89 #else // DYECMD
90 
91  int sz = ResourceManager::calcMemory(0);
92  if (tab != nullptr)
93  {
94  // TRANSLATORS: memory usage chat message
95  tab->chatLog(strprintf(_("Calculated memory usage: %d"), sz),
97  }
98 #endif // DYECMD
99 }
#define _(s)
Definition: gettext.h:34
void printMemory(const std::string &name, const int level, const int localSum, const int childsSum)
MemoryManager memoryManager
int calcMemory(const int level)
Logger * logger
Definition: logger.cpp:95
void printAllMemory(ChatTab *const tab)
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
#define PRAGMA48(str)
Definition: localconsts.h:214
int getSurfaceSize(const SDL_Surface *const surface)
void log(const char *const log_text,...)
Definition: logger.cpp:243