summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-13 00:03:20 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-13 00:03:20 +0200
commit31bf2ba85b17b9085681eb4fdaca940e6f4c17e3 (patch)
treea13b93e2ce607aa059e060e1ebaf2ba674ae1a4e
parenta71ed71be94a9fec8660ea0aa060ab9fcf7f860a (diff)
Show RSS on Linux.
-rw-r--r--src/common.hpp8
-rw-r--r--src/game/interface.cpp31
-rw-r--r--src/main.cpp29
3 files changed, 55 insertions, 13 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 3d7483d..7d3a1f9 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -28,6 +28,10 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
#include <SFML/Audio.hpp>
#include "math.hpp"
+#ifdef __linux
+#define CONFIG_SHOW_RSS
+#endif
+
#define COUNT(A) (sizeof(A) / sizeof((A)[0]))
extern bool debug_draw_cmodels;
@@ -63,6 +67,10 @@ public:
extern freq_counter_t fc_render;
extern freq_counter_t fc_game;
+#ifdef CONFIG_SHOW_RSS
+size_t sys_get_rss(void);
+#endif
+
namespace procgen {
class prng_t {
uint32_t state = 0;
diff --git a/src/game/interface.cpp b/src/game/interface.cpp
index c6d5e19..d249f38 100644
--- a/src/game/interface.cpp
+++ b/src/game/interface.cpp
@@ -371,18 +371,19 @@ void state_t::render_to(render::state_t *render)
x[1] += em;
}
- x = v2f_t(0.0f, h - em * 5.5);
- ss << "World S/T:";
- ss << game->world.stats.sectors << "/";
- ss << game->world.stats.tiles;
+ x = v2f_t(0.0f, h - em * 1.5);
+
+ ss << std::fixed << std::setprecision(3);
+ ss << "Game t/F/B: " << game->time * 1.0e-9 << "/" << game->frames << "/" << game->frames_behind;
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
- x[1] += em;
+ x[1] -= em;
ss.str(std::string());
- ss << "Awake: " << game->awake_entities.size() << "/" << game->world.stats.entities;
+ ss << std::fixed << std::setprecision(1);
+ ss << "FPS: " << fc_render.freq_ma() << ", " << fc_game.freq_ma() << " Hz";
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
- x[1] += em;
+ x[1] -= em;
ss.str(std::string());
ss << "View S/T/E: ";
ss << render->stats.sectors << "/";
@@ -390,16 +391,20 @@ void state_t::render_to(render::state_t *render)
ss << render->stats.entities;
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
- x[1] += em;
+ x[1] -= em;
ss.str(std::string());
- ss << std::fixed << std::setprecision(1);
- ss << "FPS: " << fc_render.freq_ma() << ", " << fc_game.freq_ma() << " Hz";
+ ss << "Awake: " << game->awake_entities.size() << "/" << game->world.stats.entities;
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
- x[1] += em;
+ x[1] -= em;
ss.str(std::string());
- ss << std::fixed << std::setprecision(3);
- ss << "Game t/F/B: " << game->time * 1.0e-9 << "/" << game->frames << "/" << game->frames_behind;
+ ss << "World S/T:";
+ ss << game->world.stats.sectors << "/";
+ ss << game->world.stats.tiles;
+#ifdef CONFIG_SHOW_RSS
+ ss << ", " << sys_get_rss() / 1000000.0f;
+ ss << "MB RSS";
+#endif
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
}
diff --git a/src/main.cpp b/src/main.cpp
index 1e43d76..cb6d753 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -17,6 +17,11 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
#include "common.hpp"
#include <chrono>
+#ifdef CONFIG_SHOW_RSS
+#include <sys/types.h>
+#include <unistd.h>
+#include <fstream>
+#endif
bool debug_draw_cmodels = false;
bool debug_draw_paths = false;
@@ -85,6 +90,28 @@ float freq_counter_t::freq_ma(void)
freq_counter_t fc_render = freq_counter_t(20);
freq_counter_t fc_game = freq_counter_t(10);
+#ifdef CONFIG_SHOW_RSS
+size_t sys_get_rss(void)
+{
+ std::ifstream file;
+ pid_t pid;
+ std::string line;
+ size_t res = 0;
+
+ pid = getpid();
+
+ file.open("/proc/" + std::to_string(pid) + "/status");
+ while (file >> line) {
+ if (line == "VmRSS:") {
+ file >> res;
+ break;
+ }
+ }
+
+ return res * 1024;
+}
+#endif
+
int main()
{
nclock_ref = nclock() - 1;
@@ -117,6 +144,8 @@ int main()
if (!window.isOpen())
break;
+ sys_get_rss();
+
window.clear();
render.begin_frame(now, dt);
render.render(&game);