📄 status.mx
字号:
intget_vm_cursize(lng *num){ *num = GDKvm_cursize(); return GDK_SUCCEED;}intget_vm_minsize(lng *num){ *num = GDK_vm_minsize; return GDK_SUCCEED;}intset_vm_minsize(lng *num){ @:num2sze(vm_minsize)@ if (sze < GDK_mem_bigsize) set_mem_bigsize(num); GDK_vm_minsize = MAX(GDK_mem_bigsize, sze); return GDK_SUCCEED;}intget_vm_maxsize(lng *num){ *num = GDK_vm_maxsize; return GDK_SUCCEED;}intset_vm_maxsize(lng *num){ @:num2sze(vm_maxsize)@ if (sze < GDK_vm_minsize) set_vm_minsize(num); GDK_vm_maxsize = MAX(GDK_vm_minsize, sze); return GDK_SUCCEED;}@= heap if (@2) { sz = HEAP@1size(@3); if (sz > *minsize) { sprintf(buf, "@4/%s", s); BUNins(bn, buf, &sz, FALSE); } @4 += sz; tot += sz; }@cstatus_export str SYSmem_usage(int *ret, lng *minsize);strSYSmem_usage(int *ret, lng *minsize){ lng buns = 0, hhsh = 0, thsh = 0, hind = 0, tind = 0, head = 0, tail = 0, tot = 0, n = 0, sz; BAT *bn = BATnew(TYPE_str, TYPE_lng, 2 * BBPsize); struct mallinfo m; char buf[1024]; bat i; if (bn == NULL) throw(MAL, "status.memory","Could not create BAT"); BBPlock("SYSmem_usage"); for (i = 1; i < BBPsize; i++) { BAT *b = BBP_cache(i); str s; if (!BBPvalid(i)) continue; s = BBPname(i); sz = 0; if (BBP[i].cache) sz += sizeof(BATstore); if (BBP[i].nme[0]) n += strLen(BBP[i].nme[0]); if (BBP[i].nme[1]) n += strLen(BBP[i].nme[1]); if (BBP[i].path) n += strLen(BBP[i].path); if (b) sz += sizeof(BAT); /* mirror */ if (sz > *minsize) { sprintf(buf, "desc/%s", s); BUNins(bn, buf, &sz, FALSE); } tot += (lng) sz; if (b == NULL || VIEWparent(b)) { continue; } @:heap(mem,1,b->batBuns,buns)@ @:heap(mem,b->hhash,b->hhash->heap,hhsh)@ @:heap(mem,b->thash,b->thash->heap,thsh)@ @:heap(mem,b->hheap,b->hheap,head)@ @:heap(mem,b->theap,b->theap,tail)@ } /* totals per category */ BUNins(bn, "_tot/buns", &buns, FALSE); BUNins(bn, "_tot/head", &head, FALSE); BUNins(bn, "_tot/tail", &tail, FALSE); BUNins(bn, "_tot/hhsh", &hhsh, FALSE); BUNins(bn, "_tot/thsh", &thsh, FALSE); BUNins(bn, "_tot/hind", &hind, FALSE); BUNins(bn, "_tot/tind", &tind, FALSE); /* special area 1: BBP rec */ sz = BBPlimit * sizeof(BBPrec) + n; BUNins(bn, "_tot/bbp", &sz, FALSE); tot += sz; /* this concludes all major traceable Monet memory usages */ tot += sz; BUNins(bn, "_tot/found", &tot, FALSE); /* now look at what the global statistics report (to see if it coincides) */ /* how much *used* bytes in heap? */ m = MT_mallinfo(); sz = (size_t) (m.usmblks + m.uordblks + m.hblkhd); BUNins(bn, "_tot/malloc", &tot, FALSE); /* measure actual heap size, includes wasted fragmented space and anon mmap space used by malloc() */ sz = GDKvm_heapsize(); BUNins(bn, "_tot/heap", &sz, FALSE); tot = GDKmem_cursize(); /* allocated swap area memory that is not plain malloc() */ sz = MAX(0, sz - tot); BUNins(bn, "_tot/valloc", &sz, FALSE); /* swap-area memory is in either GDKvmalloc or heap */ BUNins(bn, "_tot/swapmem", &tot, FALSE); BBPunlock("SYSmem_usage"); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *ret = bn->batCacheid; return MAL_SUCCEED;}status_export str SYSvm_usage(int *ret, lng *minsize);strSYSvm_usage(int *ret, lng *minsize){ lng buns = 0, hhsh = 0, thsh = 0, hind = 0, tind = 0, head = 0, tail = 0, tot = 0, sz; BAT *bn = BATnew(TYPE_str, TYPE_lng, 2 * BBPsize); char buf[1024]; bat i; if (bn == NULL) throw(MAL, "status.usage","Could not create BAT"); BBPlock("SYSvm_usage"); for (i = 1; i < BBPsize; i++) { BAT *b; str s; if (!BBPvalid(i)) continue; s = BBPname(i); b = BBP_cache(i); if (b == NULL || VIEWparent(b)) { continue; } @:heap(vm,1,b->batBuns,buns)@ @:heap(vm,b->hhash,b->hhash->heap,hhsh)@ @:heap(vm,b->thash,b->thash->heap,thsh)@ @:heap(vm,b->hheap,b->hheap,head)@ @:heap(vm,b->theap,b->theap,tail)@ } /* totals per category */ BUNins(bn, "_tot/buns", &buns, FALSE); BUNins(bn, "_tot/head", &head, FALSE); BUNins(bn, "_tot/tail", &tail, FALSE); BUNins(bn, "_tot/hhsh", &hhsh, FALSE); BUNins(bn, "_tot/thsh", &thsh, FALSE); BUNins(bn, "_tot/hind", &hind, FALSE); BUNins(bn, "_tot/tind", &tind, FALSE); /* special area 1: BBP rec */ sz = BBPmaxsize * sizeof(BBPrec); BUNins(bn, "_tot/bbp", &sz, FALSE); tot += sz; /* this concludes all major traceable Monet virtual memory usages */ tot += sz; BUNins(bn, "_tot/found", &tot, FALSE); /* all VM is either GDKmmap or GDKvmalloc (possibly redirected GDKmalloc), *plus* the heap */ sz = GDKvm_cursize(); BUNins(bn, "_tot/vm", &sz, FALSE); BBPunlock("SYSvm_usage"); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *ret = bn->batCacheid; return MAL_SUCCEED;}@-Additional information on the process utilization is given bythe io command. The following information is obtained.@T\begin{tabular}{| l| l|}\hlinemaxrss &the maximum resident set size utilized (in kilobytes).\\minflt &the number of page faults serviced without any I/O\\ &activity; here I/O activity is avoided by "reclaiming" a\\ &activity; here I/O activity is avoided by "reclaiming" a\\ &page frame from the list of pages awaiting reallocation.\\majflt &the number of page faults serviced that required I/O\\ &activity.\\nswap &the number of times a process was "swapped" out of main\\ &memory\\inblock &the number of times the file system had to perform input.\\oublock &the number of times the file system had to perform output.\\nvcsw &the number of times a context switch resulted due to a\\ &process voluntarily giving up the processor before its\\ &time slice was completed (usually to await availability of\\ &a resource).\\nivcsw &the number of times a context switch resulted due to a\\ &higher priority process becoming runnable or because the\\ ¤t process exceeded its time slice.\\\end{tabular}@The resource statistics are collected in a BAT. It can thenbe queried. A default listing is produced by the command @%usagecmd@.(which should be moved to Monet)The BAT grows. It should be compacted.@c#ifdef HAVE_SYS_RESOURCE_H# include <sys/resource.h>#endifstatus_export str SYSioStatistics(int *ret);strSYSioStatistics(int *ret){#ifndef NATIVE_WIN32 struct rusage ru;#endif int i; BAT *b;#ifndef NATIVE_WIN32 getrusage(RUSAGE_SELF, &ru);#endif b = BATnew(TYPE_str, TYPE_int, 32); if (b == 0) throw(MAL, "catalog.ioStatistics", "Failed to create BAT");#ifndef NATIVE_WIN32 /* store counters, ignore errors */ i = ru.ru_maxrss; BUNins(b, "maxrss", &i, FALSE); i = ru.ru_minflt; BUNins(b, "minflt", &i, FALSE); i = ru.ru_majflt; BUNins(b, "majflt", &i, FALSE); i = ru.ru_nswap; BUNins(b, "nswap", &i, FALSE); i = ru.ru_inblock; BUNins(b, "inblock", &i, FALSE); i = ru.ru_oublock; BUNins(b, "oublock", &i, FALSE); i = ru.ru_nvcsw; BUNins(b, "nvcsw", &i, FALSE); i = ru.ru_nivcsw; BUNins(b, "ninvcsw", &i, FALSE);#else i = int_nil; BUNins(b, "maxrss", &i, FALSE); BUNins(b, "minflt", &i, FALSE); BUNins(b, "majflt", &i, FALSE); BUNins(b, "nswap", &i, FALSE); BUNins(b, "inblock", &i, FALSE); BUNins(b, "oublock", &i, FALSE); BUNins(b, "nvcsw", &i, FALSE); BUNins(b, "ninvcsw", &i, FALSE);#endif if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(gdk,io)@ return MAL_SUCCEED;}status_export str SYSgdkEnv(int *ret);strSYSgdkEnv(int *ret){ int pbat = 0; int pdisk = 0; int pheat = 0; bat i; int tmp = 0, per = 0; BAT *b; b = BATnew(TYPE_str, TYPE_int, 32); if (b == 0) throw(MAL, "status.gdkEnv","Could not create BAT"); for (i = 1; i < BBPsize; i++) { if (BBPvalid(i)) { pbat++; if (BBP_cache(i)) { pheat += BBP_lastused(i); if (BBP_cache(i)->batPersistence == PERSISTENT) per++; else tmp++; } else { pdisk++; } } } b = BUNins(b, "bats", &pbat, FALSE); b = BUNins(b, "tmpbats", &tmp, FALSE); b = BUNins(b, "perbats", &per, FALSE); b = BUNins(b, "ondisk", &pdisk, FALSE); b = BUNins(b, "todisk", &BBPout, FALSE); b = BUNins(b, "fromdisk", &BBPin, FALSE); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(gdk,env)@ return MAL_SUCCEED;}status_export str SYSgdkThread(int *ret);strSYSgdkThread(int *ret){ BAT *b; int i; b = BATnew(TYPE_int, TYPE_str, THREADS); if (b == 0) throw(MAL, "catalog.gdkThread", "Failed to create BAT"); for (i = 0; i < THREADS; i++) if (GDKthreads[i].pid) { BUNins(b, &GDKthreads[i].tid, GDKthreads[i].name, FALSE); } if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(gdk,thread)@ return MAL_SUCCEED;}@-Collect the database and their access permissions for inspection.Note, this code base should be changed for the Windows setting.@c#ifndef F_OK#define F_OK 0#endifstr SYSgetDatabases(int *ret){ BAT *b; DIR *d, *db; struct dirent *e; char buf[PATHLENGTH]; FILE *f; int uid,pid; b = BATnew(TYPE_str, TYPE_str, 50); /* scan the parent for directories */ d= opendir(".."); while ( (e=readdir(d)) != NULL){ if( *e->d_name == '.') continue; snprintf(buf,PATHLENGTH,"..%c%s",DIR_SEP,e->d_name); db= opendir(buf); if( db != NULL) { snprintf(buf,PATHLENGTH,"..%c%s%c.gdk_lock",DIR_SEP,e->d_name,DIR_SEP); f= fopen(buf,"r"); if( f && fgets(buf,PATHLENGTH,f) != NULL){ sscanf(buf,"USR=%d PID=%d %s", &uid,&pid,buf); /* w00t! for platform independence! (NOT!) */ snprintf(buf,PATHLENGTH,"/proc/%d",pid); fclose(f); } else snprintf(buf,PATHLENGTH,"..%c%s%c.mguardian.pid",DIR_SEP,e->d_name,DIR_SEP); /* not water-proof, PID can exist, and be alive, but not an mserver, need to check process name */ BUNins(b,e->d_name,(access(buf,F_OK)?"sleeping":"running"), FALSE); closedir(db); } } (void) closedir(d); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(databases,mode)@ return MAL_SUCCEED;}str SYSgetPorts(int *ret, str *lang){ BAT *b; DIR *d, *db; struct dirent *e; char buf[PATHLENGTH]; FILE *f; int port; str llang; /* if lang is NULL, default to "mal" */ llang = (lang == NULL ? "mal" : *lang); b = BATnew(TYPE_str, TYPE_int, 50); /* scan the parent for directories */ d= opendir(".."); while ( (e=readdir(d)) != NULL){ if( *e->d_name == '.') continue; snprintf(buf,PATHLENGTH,"..%c%s",DIR_SEP,e->d_name); db= opendir(buf); if( db != NULL) { snprintf(buf,PATHLENGTH,"..%c%s%c.%s.port",DIR_SEP,e->d_name,DIR_SEP,llang); f= fopen(buf,"r"); if( f && fgets(buf,PATHLENGTH,f) != NULL){ port= (int) strtol(buf,NULL,10); fclose(f); } else port = 0; BUNins(b, e->d_name, (ptr)(port==0? &int_nil: &port), FALSE); closedir(db); } } (void) closedir(d); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(databases,port)@ return MAL_SUCCEED;}@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -