From e50b38a01429d41b6681db8675dc8b8f64a20c36 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 16 Jul 2016 11:47:00 +0200 Subject: [PATCH] Add a printout of mlockall() memory used, from bitter experience :-) --- main.cpp | 3 +++ mixer.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- mixer.h | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index f0f70ac..dd94d73 100644 --- a/main.cpp +++ b/main.cpp @@ -67,6 +67,9 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to lock Nageru into RAM. You probably want to\n"); fprintf(stderr, "increase \"memlock\" for your user in limits.conf\n"); fprintf(stderr, "for better realtime behavior.\n"); + uses_mlock = false; + } else { + uses_mlock = true; } int rc = app.exec(); diff --git a/mixer.cpp b/mixer.cpp index 94d09e7..327ea65 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "bmusb/bmusb.h" #include "context.h" @@ -46,6 +48,7 @@ using namespace std; using namespace std::placeholders; Mixer *global_mixer = nullptr; +bool uses_mlock = false; namespace { @@ -681,12 +684,50 @@ void Mixer::thread_func() double elapsed = now.tv_sec - start.tv_sec + 1e-9 * (now.tv_nsec - start.tv_nsec); if (frame % 100 == 0) { - printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)\n", + // check our memory usage, to see if we are close to our mlockall() + // limit (if at all set). + rusage used; + if (getrusage(RUSAGE_SELF, &used) == -1) { + perror("getrusage(RUSAGE_SELF)"); + assert(false); + } + + rlimit limit; + if (getrlimit(RLIMIT_MEMLOCK, &limit) == -1) { + perror("getrlimit(RLIMIT_MEMLOCK)"); + assert(false); + } + + printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)", frame, stats_dropped_frames, elapsed, frame / elapsed, 1e3 * elapsed / frame); // chain->print_phase_timing(); + + if (uses_mlock) { + // Check our memory usage, to see if we are close to our mlockall() + // limit (if at all set). + rusage used; + if (getrusage(RUSAGE_SELF, &used) == -1) { + perror("getrusage(RUSAGE_SELF)"); + assert(false); + } + + rlimit limit; + if (getrlimit(RLIMIT_MEMLOCK, &limit) == -1) { + perror("getrlimit(RLIMIT_MEMLOCK)"); + assert(false); + } + + printf(", using %ld / %ld MB lockable memory (%.1f%%)", + long(used.ru_maxrss / 1024), + long(limit.rlim_cur / 1048576), + float(100.0 * (used.ru_maxrss * 1024.0) / limit.rlim_cur)); + } + + printf("\n"); } + if (should_cut.exchange(false)) { // Test and clear. video_encoder->do_cut(frame); } diff --git a/mixer.h b/mixer.h index 7abbaec..e0f96cf 100644 --- a/mixer.h +++ b/mixer.h @@ -542,5 +542,6 @@ private: }; extern Mixer *global_mixer; +extern bool uses_mlock; #endif // !defined(_MIXER_H) -- 2.39.2