instrumentation

Transforming lambdas in Java 8

ε祈祈猫儿з 提交于 2019-11-28 23:27:17
Java 8 appears to generate classes to represent lambda expressions. For instance, the code: Runnable r = app::doStuff; Manifests, roughly, as: // $FF: synthetic class final class App$$Lambda$1 implements Runnable { private final App arg$1; private App$$Lambda$1(App var1) { this.arg$1 = var1; } private static Runnable get$Lambda(App var0) { return new App$$Lambda$1(var0); } public void run() { this.arg$1.doStuff(); } } As I understand this, the code is generated at runtime. Now, suppose one wanted to inject code into the run method of the above class. Experiments thus far yield a mix of

How to instrument java system classes?

和自甴很熟 提交于 2019-11-28 19:47:47
I'm trying to add custom behaviour to system classes (FileInputStream/FileOutputStream). I wrote custom ClassFileTransformer with the following transform method: public byte[] transform(ClassLoader arg0, String arg1, Class arg2, ProtectionDomain arg3, byte[] arg4) throws IllegalClassFormatException { System.out.println("class name: " + arg1); return arg4; } When I run sample program: public static void main(String[] args) throws Exception { new FileOutputStream("file"); } I see that no system classes are not passed to transform. Is there any way to modify system classes? Thanks in advance!

Instrumenting C/C++ codes using LLVM

此生再无相见时 提交于 2019-11-28 16:28:55
问题 I just read about the LLVM project and that it could be used to do static analysis on C/C++ codes using the analyzer Clang which the front end of LLVM. I wanted to know if it is possible to extract all the accesses to memory(variables, local as well as global) in the source code using LLVM. Is there any inbuilt library present in LLVM which I could use to extract this information. If not please suggest me how to write functions to do the same.(existing source code, reference, tutorial,

How to instrument java methods?

流过昼夜 提交于 2019-11-28 09:27:50
I want to write a simple java agent which can print the name of a method called by the java program instrumented. For example, my java program I want to instrument is: public class TestInstr { public static void sayHello() { System.out.println("Hello !"); } public static void main(String args[]) { sayHello(); sayHello(); sayHello(); } } I would like to display something like this : method sayHello has been called Hello ! method sayHello has been called Hello ! method sayHello has been called Hello ! Thanks for your help! You can use an instrumentation library such as Javassist to do that. Let

How to tell gcc to instrument the code with calls to my own function each _line_ of code?

对着背影说爱祢 提交于 2019-11-28 04:34:31
问题 For example, there is the source: void my_special_debugging_function(const char* function_name, const char* file_name, int line_number); void func1() { func3(); func4(); } void foo() { func1(); if(qqq) { func2(); }; func3(); func4(); for(...) { func5(); } } It should compile as: void my_special_debugging_function(const char* function_name, const char* file_name, int line_number); void func1() { my_special_debugging_function("func1", "prog.c", 3); func3(); my_special_debugging_function("func1"

Adding code to the beginning / end of methods in runtime dynamically

≯℡__Kan透↙ 提交于 2019-11-28 03:17:38
问题 I know instrumentation is a technique to add trace code dynamically into the methods to enable tracing and debugging. I was wondering if this is only a "Trace" option, hard coded into the CLR to add only trace code, or is there the ability to add any code to the methods? For example, I want to check for a condition in the beginning of every single method call in a certain class (say for permissions). Can I do this via adding dynamic code to the beginning of the methods in execution time? I'm

Trace vs Debug in .NET BCL

落爺英雄遲暮 提交于 2019-11-27 17:57:06
It seems that the System.Diagnostics.Debug , and System.Diagnostics.Trace are largely the same, with the notable exception that Debug usage is compiled out in a release configuration. When would you use one and not the other? The only answer to this I've dug up so far is just that you use the Debug class to generate output that you only see in debug configuration, and Trace will remain in a release configuration, but that doesn't really answer the question in my head. If you're going to instrument your code, why would you ever use Debug , since Trace can be turned off without a recompile? The

How to get started with WCF Performance profiling

久未见 提交于 2019-11-27 17:49:29
问题 I'm trying to figure out how to profile a WCF service so I can identify any bottlenecks. I have found a bit of information on line, but nothing that assumes no prior knowlege which is where I'm at. What are recomended FREE tools? - visual studio tools - clrprofiler Here is information I found using vsperfcmd.exe to profile wcf service and according to this it is very simple, but I need to fill in the gaps on where to start. My assumptions are to copy VsPerfCLREnv and VsPerfCmd to the server

Transforming lambdas in Java 8

那年仲夏 提交于 2019-11-27 14:55:44
问题 Java 8 appears to generate classes to represent lambda expressions. For instance, the code: Runnable r = app::doStuff; Manifests, roughly, as: // $FF: synthetic class final class App$$Lambda$1 implements Runnable { private final App arg$1; private App$$Lambda$1(App var1) { this.arg$1 = var1; } private static Runnable get$Lambda(App var0) { return new App$$Lambda$1(var0); } public void run() { this.arg$1.doStuff(); } } As I understand this, the code is generated at runtime. Now, suppose one

How to instrument java system classes?

帅比萌擦擦* 提交于 2019-11-27 12:31:14
问题 I'm trying to add custom behaviour to system classes (FileInputStream/FileOutputStream). I wrote custom ClassFileTransformer with the following transform method: public byte[] transform(ClassLoader arg0, String arg1, Class arg2, ProtectionDomain arg3, byte[] arg4) throws IllegalClassFormatException { System.out.println("class name: " + arg1); return arg4; } When I run sample program: public static void main(String[] args) throws Exception { new FileOutputStream("file"); } I see that no system