instrumentation

How to obtain instance of Instrumentation in Java

旧时模样 提交于 2020-05-13 02:27:20
问题 I am trying to write a simply ObjectUtils class that contains a variety of utility methods for all Objects. I would like to have one of them called getObjectSize(Object) where you pass it an instantiated Object and it returns the Object's size in memory: public class ObjectUtils { private static volatile Instrumentation instrumentation; public static final long getObjectSize(final Object p_oToGauge) { return instrumentation.getObjectSize(p_oToGauge); } } However, it seems that in order to

Byte Buddy Member Substitution throwing IllegalStateException error

社会主义新天地 提交于 2020-03-23 11:59:08
问题 I'm trying to write a java instrumentation agent using byte buddy. My goal is to replace a java standard library method call with a proxy call of my own. I was suggested to use Byte Buddy's MemberSubstitution to achieve this. I used this and this questions from SO for my reference. I'm using Intellij IDEA for coding. My Agent code is split into multiple files as follows: MyFirstAgent.java public class MyFirstAgent { public static void premain(String agentArgs, Instrumentation inst) { new

Counting functions in C source code

偶尔善良 提交于 2020-03-16 05:33:08
问题 I have complete project in C, which can be built with gcc or Visual Studio. There are no calls to external libraries. I would like to know how many functions there is in that project. There are no unused functions in source code, and the project comes with tests which run it with different params, so for a dynamic approach (e.g. run-time call tree) I would need to accumulate results after each test. Are there any tools that can perform static or dynamic analysis? 回答1: With gcc : $ nm elf_file

Instrumentation: Casting org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper to oracle.jdbc.OracleConnection

Deadly 提交于 2020-01-25 00:22:07
问题 I'm trying to instrument my jdbc connections. I know there are several similar questions about this topic. I tried everything but couldn't find the propper way to solve my issue so far. Also tried the answers to this question, with no result: Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper I'm working with Tomcat 7 and Java 7. Here's where I define the oracle connection pool in my context.xml

android instrumentation test case - getinstrumentation() returning null

↘锁芯ラ 提交于 2020-01-23 06:55:07
问题 I've been trying to make a test case extending intstrumentationtestcase, and whenever I call getinstrumentation() it returns a null instance of Instrumentation instead of an Instrumentation, rendering any of the automation I'm wanting to do useless. I have the permission set in the manifest as well even though I'm only testing the automation on the same app this case is going to run on...any ideas? 回答1: You need inject the instrumentation programmatically by calling injectInstrumentation

How to do Binary instrumentation of syscall brk ? (x86-64 Linux) (maybe valgrind?)

﹥>﹥吖頭↗ 提交于 2020-01-21 10:19:06
问题 I'd like to instrument syscall brk (and other calls but this in first order, it's most important to me) in given binary (preferably on actual syscall/sysenter level (x86-64 and x86) of making sys_brk call). Main goal: A part of sandbox which gives fixed amount of memory to jailed process So, I'd like to get rid of brk system calls (and most preferably others in next order) and simulate memory allocations under fixed limit . Fixed limit is memory space, available to program. (You can think

Javassist's CtMethod.insertAt(line,src) instruments code at the wrong bytecode position

限于喜欢 提交于 2020-01-16 18:34:55
问题 My goal is to insert a little bit of instrumentation code at the beginning of each basic block of code. It seems like a fairly simple task with Javaassist's ControlFlow.Block and CtMethod.insertAt(). Here's the relevant chunk of code so far (it's located in the transform function): ControlFlow flow=new ControlFlow(m); //m is the CtMethod currently being instrumented Block[] blockArray=flow.basicBlocks(); for(Block thisbb : blockArray){ //Dynamically Update Method Statistics String blockUpdate

How to expose metrics to Prometheus from a Java (Spring boot) application

给你一囗甜甜゛ 提交于 2020-01-14 14:12:09
问题 My Spring-Boot application simply has a counter metric. I just don't know how to send this information to Prometheus. I am using Maven (build tool) and Spring Boot (Java). 回答1: For Intergrating Prometheus, add the following dependencies in your POM.XML <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_spring_boot</artifactId> <version>0.1.0</version> </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_servlet</artifactId> <version>0.1.0<

renaming a field using javassist at runtime in the pre-main method (java instrumentation)

谁说我不能喝 提交于 2020-01-13 09:34:32
问题 I want to rename a field inside a java class at runtime. In addition, Any method that access that field ;wether it's read or write; I need it to be modified to use the new name instead of the old name.... All this will be done inside the pre-main method... As an Exmaple, given the following code: public class Class1 { String strCompany; public String Test() { strCompany = "TestCompany"; return strCompany; } } In the above class, I need to change the field "strCompany" to be "strCompany2", in

How to create a Python class decorator that is able to wrap instance, class and static methods?

回眸只為那壹抹淺笑 提交于 2020-01-11 19:42:06
问题 I'd like to create a Python class decorator (*) that would be able to seamlessly wrap all method types the class might have: instance, class and static. This is the code I have for now, with the parts that break it commented: def wrapItUp(method): def wrapped(*args, **kwargs): print "This method call was wrapped!" return method(*args, **kwargs) return wrapped dundersICareAbout = ["__init__", "__str__", "__repr__"]#, "__new__"] def doICareAboutThisOne(cls, methodName): return (callable(getattr