X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbctrace.C;h=930eabfc50f6bf562969812b3810c664e6782c75;hp=9a0061fe331b7f9de68677163adb58b325d62848;hb=b9f98da8f1cd8b7b31ead02fa41f299b56cac3da;hpb=21c2e6b36d6a96c2f662a89459d607b5a387f4eb diff --git a/cinelerra-5.1/guicast/bctrace.C b/cinelerra-5.1/guicast/bctrace.C index 9a0061fe..930eabfc 100644 --- a/cinelerra-5.1/guicast/bctrace.C +++ b/cinelerra-5.1/guicast/bctrace.C @@ -5,6 +5,21 @@ #include "bctrace.h" +#ifdef BOOBY +#include +#define BT_BUF_SIZE 100 +// booby trap (backtrace) +void booby() { + printf("BOOBY!\n"); + void *buffer[BT_BUF_SIZE]; + int nptrs = backtrace(buffer, BT_BUF_SIZE); + char **trace = backtrace_symbols(buffer, nptrs); + if( !trace ) return; + for( int i=0; i= 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 +200,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 +213,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(); } @@ -345,7 +360,6 @@ void BC_Trace::unset_temp(char *string) TheLock TheLocker::the_lock; TheList TheList::the_list; -TheChk TheChk::the_chk; int lock_item::table_id = 0; @@ -353,7 +367,7 @@ void TheList::dbg_add(pthread_t tid, pthread_t owner, const char *nm) { TheLocker the_locker; int i = the_list.size(); - while( --i >= 0 && the_list[i]->tid != tid ); + while( --i >= 0 && !(the_list[i]->tid == tid && the_list[i]->owner == owner) ); if( i >= 0 ) { printf("dbg_add, dup %016lx %s %s\n", (unsigned long)tid, nm, the_list[i]->name); @@ -399,3 +413,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); +} +