]> git.sesse.net Git - nageru/commitdiff
Add a printout of mlockall() memory used, from bitter experience :-)
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 16 Jul 2016 09:47:00 +0000 (11:47 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 16 Jul 2016 09:47:00 +0000 (11:47 +0200)
main.cpp
mixer.cpp
mixer.h

index f0f70ac8c71b3084284cac4a445fa1332d776178..dd94d7335cd80065a5290829404fc140fc7ffd69 100644 (file)
--- 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();
index 94d09e7eb272441dcf1dd2dfe6dde790f0baca22..327ea651318049545db28b36b98a423374a6dd44 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -27,6 +27,8 @@
 #include <utility>
 #include <vector>
 #include <arpa/inet.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 #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 7abbaec1a5e5e1273f89925d6adbedbe66f048dc..e0f96cf16a922034f4ee64bd73cca361f08d963d 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -542,5 +542,6 @@ private:
 };
 
 extern Mixer *global_mixer;
+extern bool uses_mlock;
 
 #endif  // !defined(_MIXER_H)