📄 status.mx
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f status@a M.L. Kersten, P. Boncz, N.Nes@v 2.0@+ System state information This document introduces a series of bats and operations that provide accessto information stored within the Monet Version 5 internal data structures.In all cases, pseudo BAT operation returns a transient BAT thatshould be garbage collected after being used.The main performance drain would be to use a pseudo BAT directly tosuccessively access it components. This can be avoided by first assigningthe pseudo BAT to a variable.@{@malmodule status;command cpuStatistics() :bat[:str,:int] address SYScpuStatisticscomment "Global cpu usage information";command memStatistics():bat[:str,:int] address SYSmemStatisticscomment "Global memory usage information";command ioStatistics():bat[:str,:int] address SYSioStatisticscomment "Global IO activity information";#command memMap() :void #address SYSmemMap#comment "Print a map of all memory that is in use";@-For each 64KB block in the first 3GB of the virtual memory @emph{mem_printmap()} prints a character:@multitable @columnfractions 0.05 0.7@item 0-9 @tab - thread stack space of thread <num>@item B @tab - in use for a large BAT heap (i.e. anonymous virtual memory).@item b @tab - free (last usage was B)@item S @tab - in use for a malloc block@item s @tab - free (last usage was S)@item P @tab - in use for the BBP array (i.e. anonymous virtual memory)@item p @tab - free (last usage was P)@item M @tab - in use as memory mapped region@item m @tab - free (last usage was M)@item C @tab - in use as MIL context buffer (i.e. anonymous virtual memory)@item c @tab - free (last usage was M)@end multitableOn Linux, the malloc library appears to be using anonymous virtual memory, which goes undetected. If you want to see all your memory in the map, lower the gdk_mmap threshold in monetdb5.conf to a low value (say 64KB).@-@malcommand vmStatistics(minsize:lng) :bat[:str,:lng] address SYSvm_usagecomment "Get a split-up of how much virtual memory blocks are in use.";command memUsage(minsize:lng) :bat[:str,:lng] address SYSmem_usagecomment "Get a split-up of how much memory blocks are in use.";@-Some explanation of what mem_usage() and vm_usage() display:@verbatim> m:= status.memUsage(1024:lng); io.print(m);#------------------------------## BAT: tmp_42 ## (str) (lng) ##------------------------------#[ "buns/car_category", 400012 ] 100.000 string offsets[ "buns/car_town", 400012 ] idem[ "buns/car_class", 400012 ] idem[ "tail/car_category", 266244 ] string tail heap[ "tail/car_town", 266244 ] idem[ "tail/car_class", 266244 ] idem[ "_tot/buns", 1322996 ] the three bun heaps[ "_tot/tail", 967762 ] the three tail heaps[ "_tot/head", 70984 ] negligable[ "_tot/bbp", 98866 ] BBP metadata structure[ "_tot/mil", 102400 ] MIL interpreter stack space[ "_tot/found", 2590144 ] buns+head+tail+bbp+mil[ "_tot/malloc_heap", 2956048 ] in malloc heap[ "_tot/malloc", 2956048 ] total consumed via malloc[ "_tot/valloc", 201266 ] total consumed via virtualalloc[ "_tot/mem", 3157314 ] total RAM+swap-file consumption>> v:= status.vmStatistics(1024:lng); io.print(v);#------------------------------## BAT: tmp_42 ## (str) (lng) ##------------------------------#[ "_tot/bbp", 50331648 ] 50MB reserved (100KB claimed)[ "_tot/mil", 16777216 ] 16MB reserved (100KB claimed)[ "_tot/found", 67108864 ] bbp+mil[ "_tot/vm", 71244560 ] total address space consumption>@end verbatim@+ MAL runtime status @malcommand batStatistics( ):bat[:str,:str] address SYSgdkEnvcomment "Show distribution of bats by kind";command getThreads( ):bat[:int,:str] address SYSgdkThreadcomment "Produce overview of active threads";command mem_cursize() :lng address SYSgetmem_cursizecomment "the amount of physical swapspace in KB that is currently in use";command mem_maxsize() :lng address SYSgetmem_maxsizecomment "the maximum usable amount of physical swapspace in KB (target only)";command mem_maxsize(v:lng) :void address set_mem_maxsizecomment "set the maximum usable amount of physical swapspace in KB";command vm_cursize() :lng address SYSgetvm_cursizecomment "the amount of logical VM space in KB that is currently in use";command vm_maxsize() :lng address SYSgetvm_maxsizecomment "the maximum usable amount of logical VM space in KB (target only)";command vm_maxsize(v:lng) :void address SYSsetvm_maxsizecomment "set the maximum usable amount of physical swapspace in KB";command getDatabases():bat[:str,:str]address SYSgetDatabasescomment "Produce a list of known databases in the current dbfarm";command getPorts(lang:str):bat[:str,:int]address SYSgetPortscomment "Produce a list of default ports for a specific language";@+ Implementation Code@h#ifndef _SYS_H_#define _SYS_H_#ifdef WIN32#ifndef LIBSTATUS#define status_export extern __declspec(dllimport)#else#define status_export extern __declspec(dllexport)#endif#else#define status_export extern#endifstatus_export str SYSgetDatabases(int *ret);status_export str SYSgetPorts(int *ret, str *lang);status_export int set_mem_maxsize(lng *num);#endif@-@include kprelude.mx@c#include "mal_config.h"#include "gdk.h"#include <stdarg.h>#include <time.h>#include "mal_exception.h"#include "status.h"#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_SYS_TIMES_H#include <sys/times.h>#include <stream.h>#endif#ifndef NATIVE_WIN32# ifndef HZ# if !defined(HAVE_SYSCONF) || !defined(_SC_CLK_TCK)# define HZ CLK_TCK# endif# endif#endifextern lng GDKcur_cursize(void);status_export str SYSgetmem_cursize(lng *num);strSYSgetmem_cursize(lng *num){ *num = GDKmem_cursize(); return MAL_SUCCEED;}status_export str SYSgetmem_maxsize(lng *num);strSYSgetmem_maxsize(lng *num){ *num = GDK_mem_maxsize; return MAL_SUCCEED;}status_export str SYSgetvm_cursize(lng *num);strSYSgetvm_cursize(lng *num){ *num = GDKvm_cursize(); return MAL_SUCCEED;}status_export str SYSgetvm_maxsize(lng *num);strSYSgetvm_maxsize(lng *num){ *num = GDK_vm_maxsize; return MAL_SUCCEED;}status_export str SYSsetvm_maxsize(lng *num);strSYSsetvm_maxsize(lng *num){ GDK_vm_maxsize = (size_t) *num; return MAL_SUCCEED;}/*str memMap() { MT_alloc_print(); return MAL_SUCCEED;}*/@- PerformanceTo obtain a good impression of the Monet performance we need timing information.The most detailed information is best obtained with the system profiler.However, the direct approach is to enable the user to read the timers maintainedinternally. This is done with the CPU, IO, MEMORY, and BBP command whichdisplays the elapsed time in seconds, user- and system-cpu time in millisecondssince its last invocation and the amount of space in use. The processidentifier is used to differentiate among the possible processes.Note that in multi threaded mode the routine prints the elapsedtime since the beginning of each process.@c#ifndef NATIVE_WIN32static time_t clk = 0;static struct tms state;#endifstatus_export str SYScpuStatistics(int *ret);strSYScpuStatistics(int *ret){#ifndef NATIVE_WIN32 struct tms newst;#endif int i; BAT *b;#if !defined(NATIVE_WIN32) && !defined(HZ) && defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) static int HZ; if (HZ == 0) HZ = sysconf(_SC_CLK_TCK);#endif b = BATnew(TYPE_str, TYPE_int, 32); if (b == 0) throw(MAL, "catalog.gdkCpu", "Failed to create BAT");#ifndef NATIVE_WIN32 if (clk == 0) { clk = time(0); times(&state); } times(&newst); /* store counters, ignore errors */ i = (int) (time(0) - clk); b = BUNins(b, "elapsed", &i, FALSE); i = newst.tms_utime * 1000 / HZ; b = BUNins(b, "user", &i, FALSE); i = (newst.tms_utime - state.tms_utime) * 1000 / HZ; b = BUNins(b, "elapuser", &i, FALSE); i = newst.tms_stime * 1000 / HZ; b = BUNins(b, "system", &i, FALSE); i = (newst.tms_stime - state.tms_stime) * 1000 / HZ; b = BUNins(b, "elapsystem", &i, FALSE); state = newst;#else i = int_nil; b = BUNins(b, "elapsed", &i, FALSE); b = BUNins(b, "user", &i, FALSE); b = BUNins(b, "elapuser", &i, FALSE); b = BUNins(b, "system", &i, FALSE); b = BUNins(b, "elapsystem", &i, FALSE);#endif if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(gdk,cpu)@ return MAL_SUCCEED;}@-Same observations as to SYScpuStatistics()@cstatic char *memincr = NULL;status_export str SYSmemStatistics(int *ret);strSYSmemStatistics(int *ret){ struct mallinfo m; BAT *b; int i; m = MT_mallinfo(); b = BATnew(TYPE_str, TYPE_int, 32); if (b == 0) throw(MAL, "catalog.memStatistics", "Failed to create BAT"); /* store counters, ignore errors */ if (memincr == NULL) { memincr = MT_heapbase; } i = (MT_heapcur() - memincr); memincr = MT_heapcur(); b = BUNins(b, "memincr", &i, FALSE); i = m.arena; b = BUNins(b, "arena", &i, FALSE); i = m.ordblks; b = BUNins(b, "ordblks", &i, FALSE); i = m.smblks; b = BUNins(b, "smblks", &i, FALSE); i = m.hblkhd; b = BUNins(b, "hblkhd", &i, FALSE); i = m.hblks; b = BUNins(b, "hblks", &i, FALSE); i = m.usmblks; b = BUNins(b, "usmblks", &i, FALSE); i = m.fsmblks; b = BUNins(b, "fsmblks", &i, FALSE); i = m.uordblks; b = BUNins(b, "uordblks", &i, FALSE); i = m.fordblks; b = BUNins(b, "fordblks", &i, FALSE); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); @:Pseudo(gdk,mem)@ return MAL_SUCCEED;}@-To avoid complains about signed/unsigned comparisons between lng & size_t,we cast lng *num to size_t sze,after checking that there is no under-/overflow.@c@= num2sze size_t sze; if (*num < 0) { GDKerror("set_@1: new size must not be < 0!\n"); return GDK_FAIL; }#if SIZEOF_SIZE_T == SIZEOF_INT{ lng size_t_max = 2 * (lng)INT_MAX; if (*num > size_t_max) { GDKerror("set_@1: new size must not be > " LLFMT "!\n", size_t_max); return GDK_FAIL; }}#endif sze = (size_t)*num;@cintget_mem_bigsize(lng *num){ *num = GDK_mem_bigsize; return GDK_SUCCEED;}intset_mem_bigsize(lng *num){ @:num2sze(mem_bigsize)@ GDK_mem_bigsize = MAX(32768, sze); return GDK_SUCCEED;}intget_mem_cursize(lng *num){ *num = GDKmem_cursize(); return GDK_SUCCEED;}intget_mem_maxsize(lng *num){ *num = GDK_mem_maxsize; return GDK_SUCCEED;}intset_mem_maxsize(lng *num){ @:num2sze(mem_maxsize)@ if (sze < GDK_mem_bigsize) set_mem_bigsize(num); GDK_mem_maxsize = MAX(GDK_mem_bigsize, sze); return GDK_SUCCEED;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -