如何追踪服务火鸟 [英] How to trace service firebird

查看:83
本文介绍了如何追踪服务火鸟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用delphi xe10跟踪服务Firebird服务器的所有事件?这是我的代码:

How to trace all events for service firebird server with delphi xe10? This is my code:

my := TIBControlService.Create(Self);

my.ServerName := '127.0.0.1/3050';
my.Protocol := TProtocol.TCP;

my.LoginPrompt := false;
my.TraceFlags := [tfQPrepare, tfQExecute, tfQFetch, tfError, tfStmt, tfConnect, tfTransact, tfBlob, tfService, tfMisc];

my.Params.Add( 'user_name=SYSDBA' );
my.Params.Add( 'password=masterkey' );

// -----
mh := MonitorHook;
mh.TraceFlags := my.TraceFlags;

Self.IBSQLMonitor1.TraceFlags := my.TraceFlags;
mh.RegisterMonitor(Self.IBSQLMonitor1);

Self.IBSQLMonitor1.Enabled := true;
Memo1.Lines.Add( Format('GetMonitorCount: %d',[mh.GetMonitorCount]) );


my.Attach;

Memo1.Lines.Add( Format('Active: %s',[System.StrUtils.IfThen(my.Active,'yes','no')]) );

procedure TForm1.IBSQLMonitor1SQL(EventText: string; EventTime: TDateTime);
begin
    Memo1.Lines.Add(EventText);
end;

结果:

GetMonitorCount: 1
Active: yes

[Application:]
:[Attach]

[Application:]
:[Query]

但是此结果仅来自我的应用程序.当我从另一个过程(例如isql)进行连接时,我的应用程序未显示此事件.

But this result is only from my application. When I connecting from another proces (ex.isql) my application not show this event.

推荐答案

  1. 在谈论Interbase/Firebird时,术语 EVENT 具有非常特殊的含义,即将文本常量发送给预订了该常量的客户端的特定SQL命令.

  1. When talking about Interbase/Firebird the term EVENT has a very specific meaning, the specific SQL command that sends text constants to clients, who subscribed to those.

请参见http://firebirdsql.org/file/documentation/reference_manuals/fblangref25-zh-CN/html/fblangref25-psql-coding.html#fblangref25-psql-postevent

但是,客户端应该订阅与PSQL块所发布的完全相同的文本字符串.有人谈论启用基于掩码的订阅,这有可能使订阅所有SQL事件成为可能,例如 *.* 匹配Windows中的所有文件,但就我所知,它们从未实现

However, the client should subscribe to the exactly the same text string, as posted by PSQL block. There were talks about enabling masks-based subscription, which would potentially made it possible to subscribe to all SQL events, like *.* matches all files in Windows, but for the best of my knowledge they never materialized.

这是事件"在Firebird中的含义,但似乎不是您所要的,而是看起来您想监视从SQL命令开始的,在SQL Server和所有应用程序之间流动的所有类型的活动.还有更多

That is what "event" means in Firebird, but it does not seem that is what you mean, instead it looks you want to monitor all the kinds of activity flowing between the SQL server and all the applications, starting with SQL commands and more.

如果是这样,那么通常就没有办法这样做.您必须决定到底要什么以及为什么要这么做,也许会有一些部分解决方案.

If so, then there is no way to do it in general. You have to decide what exactly and why exactly do you want, and maybe there will be some partial solutions.

Firebird 2.5引入了所谓的 Trace API ,该API可让您订阅某些动作并收到通知.不过,这往往会给引擎带来很大的负担,具体取决于订阅过滤器的模糊程度以及服务器接收的请求数量-可能会增加RAM和CPU使用率,直至完全无法使用.

Firebird 2.5 introduced the so called Trace API, which allows you to subscribe to SOME of actions and be notified of them. This tends to introduce a significant load on the engine though, depending on how vague your subscription filters would be and how many requests the server receives - it might increase RAM and CPU usage up to total unusability.

  • 可以订阅的活动类型受到限制.例如,不监视读取BLOB的过程.当我问-我在为由 Delphi dbExpress 库怪癖触发的臭名昭著的无效BLOB ID"而苦苦挣扎时,我被告知没有人需要它,而且您几乎没有理由需要它"您也做了一个演示项目,并将其发送给我们-我们为您解释了行为".这段时间使用BLOB访问跟踪将对我有很大帮助,但客观地说,那是我真正需要的唯一情况.

  • The kinds of activity that can be subscribed for are limited. For example the process of reading BLOBs is not monitored. When I asked - I was struggling with the infamous "Invalid BLOB id" that was triggered by Delphi dbExpress library quirk - i was told that "no one ever needed this, and you have little reasons to need it too. You made a demo project, sent it to us - and we explained the behavior for you". THAT time having BLOBs access tracing would help me a lot, but to be objective, that was one and the only case I really needed it.

您可能会看看使用 Firebird Trace Manager (从2.5开始的FB发行版的一部分)的CLI实用程序可以大致得到什么.

You might take a look at what you can get in general with Firebird Trace Manager - a CLI utility that is part of FB distribution, starting with 2.5.

您可以查看 Firebird Profiler ,它是http://fbprofiler.sf.net

用于Firebird的商业DB IDE(例如IBExpert或UpScene TraceManager,可能还有其他)通常都具有Trace API支持.

Commercial DB IDEs for Firebird, like IBExpert or UpScene TraceManager and probably others too, usually have Trace API support.

您可以使用Trace API进行自己的实现,从 Program Files \ Firebird \ Firebird_2_5 \ doc \ README.trace_services.txt Program Files \ Firebird \ Firebird_2_5开始\ include \ ibase.h .也可能发生了 Unified Interbase IBObjects 之类的第三方库将API转换为Delphi.我想我在 UIB 中看到了有关跟踪的信息,但我不确定.我不希望这样的库成为 Delphi 发行版的一部分:从 Delphi 的观点来看, Firebird 是其 Interbase <的直接竞争对手./em>和 IBX 库几乎没有兴趣通过仅支持 Firebird 的功能来脱离自己的 Interbase .

You may do your own implementation, using Trace API, starting with Program Files\Firebird\Firebird_2_5\doc\README.trace_services.txt and Program Files\Firebird\Firebird_2_5\include\ibase.h. It may also happen that 3rd party libraries like Unified Interbase or IBObjects have translated the API to Delphi. I think i saw something about trace in UIB but i am not sure. I would not expect though such a library to be part of Delphi distribution: from Delphi standpoint Firebird is direct competitor to their Interbase and IBX library would hardly have interest to diverge from their own Interbase by supporting Firebird-only functions.

只要您只关心诸如Delphi之类的本机应用程序,您可能会决定制作自己的中介程序 fbclient.dll 并将其安装在所有客户端计算机上,而不是库存的DLL.如果您的应用使用了旧版模拟 GDS32.DLL ,则该操作相同.

Provided you only care about native applications like Delphi you might decide to make your own interposer fbclient.dll and install it on all the client computers instead of stock DLLs. Same for legacy-emulating GDS32.DLL, if used by your apps.

  • 此DLL应该完全提供所有API调用,都是IB6文档中 http://firebirdsql.org/en/reference-manuals/,包含所有IB6之后的更新,以及新的Firebird 3面向对象的API".
  • 它应以您选择的方式记录调用,然后将调用代理到原始客户端DLL的副本,该副本将使用不同的文件名为其隐藏.您应该在每台要拦截和监视的计算机上安装该文件,而不是安装标准客户端DLL.
  • 使用经典API并不难,尽管没有发布,但人们正在这样做.但是新的ooAPI可能具有挑战性.
  • 它将仅通过 fbclient.DLL 接口拦截应用程序.使用 Jaybird 的Java应用程序和使用 .Net Provider 库的C#应用​​程序可能会使用基础的 wire协议,而跳过 fbclient.dll 以及您的插入者.
  • This DLL should totally provide all the API calls, both classic ones described in IB6 documentation at http://firebirdsql.org/en/reference-manuals/ with all the post-IB6 updates, and the new Firebird 3 "object oriented API".
  • It should log the calls in a way of your choosing, and then should proxy the call to the copy of original client DLL that you will hide for it with different file name. It should be installed instead of the standard client DLL on every computer you care to intercept and monitor.
  • It should not be very hard with the classic API, people were doing this, though did not publish. But the new ooAPI might be challenging.
  • It will only intercept applications, working through the fbclient.DLL interface. Java applications using Jaybird and C# applications using .Net Provider libraries would probably use underlying wire protocol skipping the fbclient.dll and thus your interposer too.

这篇关于如何追踪服务火鸟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆