add grabshot, move snapshot, asset update mtime, plugins.txt for ffmpeg 3.4.1
[goodguy/history.git] / cinelerra-5.1 / guicast / bctrace.C
index ee1c6fa0b782184f5aa5f6737fea966306f09796..c50fff5f45acd2ce4681f222374fe77ebac9c753 100644 (file)
@@ -19,7 +19,7 @@ BC_Trace::~BC_Trace()
 bc_trace_mutex execution_table;
 bc_trace_mutex memory_table;
 bc_trace_mutex lock_table;
-bc_trace_list lock_free;
+bc_trace_list  lock_free;
 bc_trace_mutex file_table;
 
 // incase lock set after task ends
@@ -28,7 +28,7 @@ static const char *last_lock_title = 0;
 static const char *last_lock_location = 0;
 
 trace_item::trace_item(bc_trace_t &t) : table(t) { ++table.size; }
-trace_item::~trace_item() { --table.size; } 
+trace_item::~trace_item() { --table.size; }
 
 extern "C" void dump()
 {
@@ -114,12 +114,12 @@ int BC_Trace::set_lock(const char *title, const char *loc, trace_info *info)
        last_lock_title = title;
        last_lock_location = loc;
        lock_item *it;
-       if( lock_table.size >= TOTAL_LOCKS ) {
+       if( (it=(lock_item*)lock_free.first) != 0 )
+               lock_free.remove_pointer(it);
+       else if( lock_table.size >= TOTAL_LOCKS ) {
                it = (lock_item*)lock_table.first;
                lock_table.remove_pointer(it);
        }
-       else if( (it=(lock_item*)lock_free.first) != 0 )
-               lock_free.remove_pointer(it);
        else
                it = new lock_item();
        it->set(info, title, loc);
@@ -185,7 +185,7 @@ void BC_Trace::unset_all_locks(trace_info *info)
        while( p ) {
                lock_item *lp = p;  p = (lock_item*)p->next;
                if( lp->info != info ) continue;
-               lock_table.remove_pointer(p);  lock_free.append(p);
+               lock_table.remove_pointer(lp);  lock_free.append(lp);
        }
        lock_table.unlock();
 }
@@ -198,7 +198,7 @@ void BC_Trace::clear_locks_tid(pthread_t tid)
        while( p ) {
                lock_item *lp = p;  p = (lock_item*)p->next;
                if( lp->tid != tid ) continue;
-               lock_table.remove_pointer(p);  lock_free.append(p);
+               lock_table.remove_pointer(lp);  lock_free.append(lp);
        }
        lock_table.unlock();
 }
@@ -399,3 +399,49 @@ void BC_Trace::dump_threads(FILE *fp)
 }
 
 
+void BC_Trace::dump_shm_stat(const char *fn, FILE *fp)
+{
+       char path[BCTEXTLEN];
+       sprintf(path, "/proc/sys/kernel/%s",fn);
+       FILE *sfp = fopen(path,"r");
+       if( !sfp ) return;
+       uint64_t v = 0;
+       fscanf(sfp, "%ju", &v);
+       fclose(sfp);
+       fprintf(fp, "%s = %ju\n", fn, v);
+}
+
+void BC_Trace::dump_shm_stats(FILE *fp)
+{
+       dump_shm_stat("shmall", fp);
+       dump_shm_stat("shmmax", fp);
+       dump_shm_stat("shmmni", fp);
+       FILE *sfp = fopen("/proc/sysvipc/shm","r");
+       if( !sfp ) return;
+       char line[BCTEXTLEN];
+       int pid = getpid();
+       if( !fgets(line,sizeof(line), sfp) ) return;
+       int64_t used = 0, other = 0;
+       int n_used = 0, n_other = 0;
+       while( fgets(line,sizeof(line), sfp) ) {
+               int key, shmid, perms, cpid, lpid, uid, gid, cuid, cgid;
+               int64_t size, nattch, atime, dtime, ctime, rss, swap;
+               if( sscanf(line,
+                       "%d %d %o %ju %u %u %ju %u %u %u %u %ju %ju %ju %ju %ju",
+                       &key, &shmid, &perms, &size, &cpid, &lpid, &nattch,
+                       &uid, &gid, &cuid, &cgid, &atime, &dtime, &ctime,
+                       &rss, &swap) != 16 ) break;
+               if( cpid == pid ) {
+                       used += size;
+                       ++n_used;
+               }
+               else {
+                       other += size;
+                       ++n_other;
+               }
+       }
+       fclose(sfp);
+       fprintf(fp, "shmused = %jd (%d items)\n", used, n_used);
+       fprintf(fp, "shmother = %jd (%d items)\n", other, n_other);
+}
+