什么是仪器? [英] What is instrumentation?

查看:80
本文介绍了什么是仪器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过这个术语在与日志记录相同的上下文中使用了很多,但是我似乎找不到确切的定义.

I've heard this term used a lot in the same context as logging, but I can't seem to find a clear definition of what it actually is.

这仅仅是记录/监视工具和活动的更一般的一类吗?

Is it simply a more general class of logging/monitoring tools and activities?

请提供何时/如何使用仪器的示例代码/场景.

Please provide sample code/scenarios when/how instrumentation should be used.

推荐答案

我编写了执行检测的工具.所以这就是我的想法.

I write tools that perform instrumentation. So here is what I think it is.

  • DLL重写.这就是Purify和Quantify之类的工具.先前对此问题的答复说,他们检测后编译/链接.那是不对的. Purify and Quantify会在编译/链接循环后首次执行DLL时对其进行检测,然后缓存结果,以便下次可以更快地使用它.对于大型应用程序,对DLL进行性能分析可能会非常耗时.这也是有问题的-在我曾于1998年至2000年间工作的一家公司中,我们有一个大型的200万行应用程序,需要花费4个小时进行检测,并且其中2个DLL在检测期间会随机崩溃,如果任何一个失败,您都将删除他们两个,然后重新开始.

  • DLL rewriting. This is what tools like Purify and Quantify do. A previous reply to this question said that they instrument post-compile/link. That is not correct. Purify and Quantify instrument the DLL the first time it is executed after a compile/link cycle, then cache the result so that it can be used more quickly next time around. For large applications, profiling the DLLs can be very time consuming. It is also problematic - at a company I worked at between 1998-2000 we had a large 2 million line app that would take 4 hours to instrument, and 2 of the DLLs would randomly crash during instrumentation and if either failed you would have do delete both of them, then start over.

就地检测.这与DLL重写相似,除了不修改DLL且磁盘上的映像保持不变. DLL函数被适当地挂钩到首次加载DLL时(在启动过程中或调用LoadLibrary(Ex)之后)所需的任务.您可以在Microsoft Detours库中看到与此类似的技术.

In place instrumentation. This is similar to DLL rewriting, except that the DLL is not modified and the image on the disk remains untouched. The DLL functions are hooked appropriately to the task required when the DLL is first loaded (either during startup or after a call to LoadLibrary(Ex). You can see techniques similar to this in the Microsoft Detours library.

即时检测.与就地类似,但仅在第一次执行该方法时才实际检测该方法.这比就地更复杂,并且将仪器惩罚延迟到第一次遇到该方法之前.取决于您正在做什么,这可能是好事,也可能是坏事.

On-the-fly instrumentation. Similar to in-place but only actually instruments a method the first time the method is executed. This is more complex than in-place and delays the instrumentation penalty until the first time the method is encountered. Depending on what you are doing, that could be a good thing or a bad thing.

中间语言工具.这通常是使用Java和.Net语言(C〜,VB.Net,F#等)完成的.该语言被编译为中间语言,然后由虚拟机执行.虚拟机提供了一个接口(用于Java的JVMTI,用于.Net的ICorProfiler(2)),可用于监视虚拟机的运行情况.这些选项中的一些选项使您可以在将中间语言编译为可执行指令之前对其进行修改.

Intermediate language instrumentation. This is what is often done with Java and .Net languages (C~, VB.Net, F#, etc). The language is compiled to an intermediate language which is then executed by a virtual machine. The virtual machine provides an interface (JVMTI for Java, ICorProfiler(2) for .Net) which allows you to monitor what the virtual machine is doing. Some of these options allow you to modify the intermediate language just before it gets compiled to executable instructions.

通过反射的中间语言检测. Java和.Net都提供了反射API,这些API允许发现有关方法的元数据.使用这些数据,您可以即时创建新方法并检测现有方法,就像前面提到的中间语言检测一样.

Intermediate language instrumentation via reflection. Java and .Net both provide reflection APIs that allow the discovery of metadata about methods. Using this data you can create new methods on the fly and instrument existing methods just as with the previously mentioned Intermediate language instrumentation.

编译时检测.在编译时使用此技术,以在编译过程中将适当的指令插入应用程序. Visual Studio的概要分析功能不经常使用,可以提供此功能.需要完整的重建和链接.

Compile time instrumentation. This technique is used at compile time to insert appropriate instructions into the application during compilation. Not often used, a profiling feature of Visual Studio provides this feature. Requires a full rebuild and link.

源代码检测.此技术用于修改源代码以插入适当的代码(通常是有条件地编译,因此您可以将其关闭).

Source code instrumentation. This technique is used to modify source code to insert appropriate code (usually conditionally compiled so you can turn it off).

链接时间检测.该技术仅在用跟踪分配器替换默认内存分配器时才真正有用.早期的例子是1990年代初期在Solaris/HP上的Sentinel内存泄漏检测器.

Link time instrumentation. This technique is only really useful for replacing the default memory allocators with tracing allocators. An early example of this was the Sentinel memory leak detector on Solaris/HP in the early 1990s.

各种现成的和即时的检测方法充满了危险,因为很难安全地停止所有线程并修改代码而又不冒要求可能要访问锁的API调用的风险.它由您刚刚暂停的线程持有-您不想这样做,将会陷入僵局.您还必须检查是否有其他线程正在执行该方法,因为如果是,则无法对其进行修改.

The various in-place and on-the-fly instrumentation methods are fraught with danger as it is very hard to stop all threads safely and modify the code without running the risk of requiring an API call that may want to access a lock which is held by a thread you've just paused - you don't want to do that, you'll get a deadlock. You also have to check if any of the other threads are executing that method, because if they are you can't modify it.

基于虚拟机的检测方法更易于使用,因为虚拟机可确保您可以安全地修改代码.

The virtual machine based instrumentation methods are much easier to use as the virtual machine guarantees that you can safely modify the code at that point.

  • (编辑-稍后添加此项目)IAT挂钩工具.这涉及为其他DLL/共享库中链接的功能修改导入addess表.这类检测可能是最简单的工作方法,您不需要知道如何反汇编和修改现有的二进制文件,也不需要使用虚拟机操作码执行相同的操作.您只需使用自己的函数地址修补导入表,然后从钩子中调用实函数.在许多商业和开源工具中使用.

我认为我已经涵盖了所有内容,希望能对您有所帮助.

I think I've covered them all, hope that helps.

这篇关于什么是仪器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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