⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profiler.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 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 profiler@a Martin Kersten@+ Performance profilerA key issue in developing fast programs using the Monet databaseback-end requires a keen eye on where performance is lost.Although performance tracking and measurements are highlyapplication dependent, a simple to use tool makes lifea lot easier.Inspired by programs like xosview and xload, weprovide a simple Java application that reads a streamof log events generated by the Monet kernel upon request.Activation of the performance monitor has a global effect,i.e. all concurrent actions on the kernel are traced,but the events are only sent to the client initiated the profiler thread.@- Monet Event LoggerThe Monet Event Logger generates records of each event ofinterest indicated by a log filter, i.e. a pattern overmodule and function names. The log record contents is derived from counters being(de-)activated. A complete list of recognized counters is shown below.@- Execution tracingTracing is a special kind of profiling, where the informationgathered is not sent to a remote system, but stored in the databaseitself. Each profile event is given a separate BAT@verbatim# thread and time since startprofiler.activate("tick");	# cpu time in nano-seconds profiler.activate("cpu");	# memory allocation informationprofiler.activate("memory");# IO activityprofiler.activate("io"); # Module,function,program counterprofiler.activate("pc"); # actual MAL instruction executedprofiler.activate("statement");	@end verbatim@-The profiler event can be handled in several ways.The default strategy is to ship the event record immediately over a streamto a performance monitor, eg. Mknife.An alternative strategy is preparation of off-line performance analysis.For this case the event record is turned into a XML structure andsent over the stream (most likely linked with a file)or the information is gathered in a BAT group for online analysis.To reduce the  interference of performance measurement withthe experiments, the user can use an event cache, which isemptied explicitly upon need.@malmodule profiler;command activate(name:str):voidaddress CMDactivateProfilercomment "Make the specified counter active.";command deactivate(name:str):voidaddress CMDdeactivateProfilercomment "Deactivate the counter";command openStream():void address CMDopenProfilerStreamcomment "Sent the events to output stream";command openStream(fnme:str)address CMDsetProfilerStreamcomment "Send the log events to a file ";command closeStream():void address CMDcloseProfilerStreamcomment "Stop sending the event records";command setAll():voidaddress CMDsetAllProfilercomment "Short cut for setFilter(*,*).";command setNone():voidaddress CMDsetNoneProfilercomment "Short cut for clrFilter(*,*).";command setFilter(mod:str,fcn:str):voidaddress CMDsetFilterProfilercomment "Generate an event record for all 	function calls that satisfy the regular 	expression mod.fcn. A wildcard (*) can 	be used as name to identify all";command clrFilter(mod:str,fcn:str):voidaddress CMDclrFilterProfilercomment "Clear the performance trace bit 	of the selected functions.";command setStartPoint(mod:str,fcn:str):voidaddress CMDstartPointProfilercomment "Start performance tracing at mod.fcn";command setEndPoint(mod:str,fcn:str)address CMDendPointProfilercomment "End performance tracing after mod.fcn";command start():voidaddress CMDstartProfilercomment "Start performance tracing";command stop():voidaddress CMDstopProfilercomment "Stop performance tracing";command clearTrace():voidaddress CMDclearTracecomment "Clear the profiler tables";command startTrace():voidaddress CMDstartTracecomment "Prepare for online tracing using the profile filter";command stopTrace():voidaddress CMDstopTracecomment "Stop online tracing";command setCachedProfiling():voidaddress CMDsetCachedProfilingcomment "use cached events rather then online";command setOnlineProfiling():voidaddress CMDsetOnlineProfilingcomment "Sent events over stream";command setOfflineProfiling():voidaddress CMDsetOfflineProfilingcomment "Sent events over stream";command dumpTrace():voidaddress CMDdumpTracecomment "List the events collected";command getTrace(e:str):bat[:int,:any_1]address CMDgetTracecomment "Get the trace details of a specific event";command cleanup():voidaddress CMDcleanupcomment "Remove the temporary tables for profiling";@{@-@+ ImplementationThe commands merely encapsulate the functionality provided bymal_profiler, which should be explicitly compiled with the kernel, becauseits generates a noticable overhead.@h#include "gdk.h"#include <stdarg.h>#include <time.h>#include "mal_stack.h"#include "mal_resolve.h"#include "mal_exception.h"#include "mal_client.h"#include "mal_profiler.h"@-Using the Monet Performance Profiler is constrained by the mal_profiler.@c#include "mal_config.h"#include "profiler.h"#ifdef WIN32#ifndef LIBPROFILER#define profiler_export extern __declspec(dllimport)#else#define profiler_export extern __declspec(dllexport)#endif#else#define profiler_export extern#endifprofiler_export str CMDactivateProfiler(int *res, str *name);profiler_export str CMDdeactivateProfiler(int *res, str *name);profiler_export str CMDsetFilterProfiler(int *res, str *mod, str *fcn);profiler_export str CMDsetAllProfiler(int *res);profiler_export str CMDclrFilterProfiler(int *res, str *mod, str *fcn);profiler_export str CMDsetNoneProfiler(int *res);profiler_export str CMDsetProfilerStream(int *res, str *fnme);profiler_export str CMDstartPointProfiler(int *res, str *mod, str *fcn);profiler_export str CMDendPointProfiler(int *res, str *mod, str *fcn);profiler_export str CMDstopProfiler(int *res);profiler_export str CMDstartProfiler(int *res);profiler_export str CMDstartTrace(int *res);profiler_export str CMDstopTrace(int *res);profiler_export str CMDclearTrace(int *res);profiler_export str CMDdumpTrace(int *res);profiler_export str CMDgetTrace(int *res, str *ev);profiler_export str CMDsetCachedProfiling(int *ret);profiler_export str CMDsetOnlineProfiling(int *ret);profiler_export str CMDsetOfflineProfiling(int *ret);profiler_export str CMDopenProfilerStream(int *res);profiler_export str CMDcloseProfilerStream(int *res);profiler_export str CMDcleanup(int *ret);#define checkProfiler(X) \	if( ! profilerAvailable()) \	throw(MAL, "profiler." X,\	":Monet not compiled for performance monitoring");strCMDactivateProfiler(int *res, str *name){	(void) res;		/* fool compiler */	checkProfiler("activate");	activateCounter(*name);	return MAL_SUCCEED;}strCMDdeactivateProfiler(int *res, str *name){	(void) res;		/* fool compiler */	checkProfiler("deactivate");	deactivateCounter(*name);	return MAL_SUCCEED;}strCMDsetFilterProfiler(int *res, str *mod, str *fcn){	(void) res;		/* fool compiler */	checkProfiler("setFilter");	setFilter(MCgetClient()->nspace, *mod, *fcn);	return MAL_SUCCEED;}strCMDsetAllProfiler(int *res){	str x = GDKstrdup("*");	str y = GDKstrdup("*");	(void) res;		/* fool compiler */	return CMDsetFilterProfiler(res, &x, &y);}strCMDopenProfilerStream(int *res){	(void) res;	return openProfilerStream();}strCMDcloseProfilerStream(int *res){	(void) res;	return closeProfilerStream();}strCMDclrFilterProfiler(int *res, str *mod, str *fcn){	(void) res;		/* fool compiler */	checkProfiler("clrFilter");	resetFilter(MCgetClient()->nspace, *mod, *fcn);	return MAL_SUCCEED;}strCMDsetNoneProfiler(int *res){	str x = GDKstrdup("");	str y = GDKstrdup("");	(void) res;		/* fool compiler */	return CMDclrFilterProfiler(res, &x, &y);}strCMDsetProfilerStream(int *res, str *fnme){	(void) res;		/* fool compiler */	checkProfiler("setProfiler");	setLogFile(MCgetClient()->nspace, *fnme);	return MAL_SUCCEED;}strCMDstartPointProfiler(int *res, str *mod, str *fcn){	(void) res;		/* fool compiler */	checkProfiler("startPoint");	setStartPoint(MCgetClient()->nspace, *mod, *fcn);	return MAL_SUCCEED;}strCMDendPointProfiler(int *res, str *mod, str *fcn){	(void) res;		/* fool compiler */	checkProfiler("endPoint");	setStartPoint(MCgetClient()->nspace, *mod, *fcn);	return MAL_SUCCEED;}strCMDstopProfiler(int *res){	Client c = MCgetClient();	(void) res;		/* fool compiler */	checkProfiler("stop");	stream_printf(c->fdout, "# Performance profiling stopped\n");	stopProfiling();	return MAL_SUCCEED;}strCMDstartProfiler(int *res){	Client c = MCgetClient();	(void) res;		/* fool compiler */	checkProfiler("start");	stream_printf(c->fdout, "# Start performance profiling\n");	startProfiling();	return MAL_SUCCEED;}@-Tracing an active system.@cstrCMDstartTrace(int *res){	(void) res;		/* fool compiler */	checkProfiler("start");	startTrace();	return MAL_SUCCEED;}strCMDstopTrace(int *res){	(void) res;		/* fool compiler */	checkProfiler("stop");	stopTrace();	return MAL_SUCCEED;}strCMDclearTrace(int *res){	(void) res;		/* fool compiler */	checkProfiler("stop");	clearTrace();	return MAL_SUCCEED;}strCMDdumpTrace(int *res){	(void) res;		/* fool compiler */	checkProfiler("dump");	stopTrace();	return MAL_SUCCEED;}strCMDgetTrace(int *res, str *ev){	BAT *bn;	(void) res;		/* fool compiler */	checkProfiler("dump");	bn = getTrace(*ev);	if (bn) {		BBPincref(*res = bn->batCacheid, TRUE);		return MAL_SUCCEED;	}	throw(MAL, "getTrace", "Failed to find event profile");}strCMDsetCachedProfiling(int *ret){	(void) ret;	setCachedProfiling();	return MAL_SUCCEED;}strCMDsetOnlineProfiling(int *ret){	(void) ret;	setOnlineProfiling();	return MAL_SUCCEED;}strCMDsetOfflineProfiling(int *ret){	(void) ret;	setOnlineProfiling();	return MAL_SUCCEED;}strCMDcleanup(int *ret){	(void) ret;	cleanupProfiler();	return MAL_SUCCEED;}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -