Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't track object creation #356

Closed
RoySunnySean007 opened this issue Aug 13, 2018 · 10 comments
Closed

Can't track object creation #356

RoySunnySean007 opened this issue Aug 13, 2018 · 10 comments

Comments

@RoySunnySean007
Copy link

RoySunnySean007 commented Aug 13, 2018

Hi All,

I refer to #252 to do a hello world to track all object allocation, and I use the following code in #252.
BTrace code version: 1.3.11
Expected behavior: It will print my test message "Roytest" for every new object allocation.
Actually behavior: It doesn't print anything.

I did a simple test, use "java.util.HashMap" to replace "+java.lang.Object", it will print related message like below:

roytest
java.util.HashMap 64

Btrace code:

import com.sun.btrace.annotations.;
import static com.sun.btrace.BTraceUtils.
;

@btrace
public class BHello {
@OnMethod(clazz = "+java.lang.Object", method = "")
public static void onNewThing(@self Object o, @ProbeClassName String pcn) {
println("Roytest");
Class objectClass = Reflective.classOf(o);
String objectClassString = Reflective.name(objectClass);

        if (Strings.compareTo(pcn, objectClassString) == 0) {
            print(pcn);
            print('\t');
            println(Strings.str(sizeof(o)));
            
        }
}

}

Really appreciated ur help in advance!

My task: track big object allocation and its stacktrace, it would be great if you could provide comment on it as well :)

Thanks,
Roy

@jbachorik
Copy link
Collaborator

I hate to bring you the bad news but BTrace is not an optimal tool for this. You would need something operating at the native level and completely off the Java heap. This kind of instance tracking is good only for 'hello world' like applications :/

Regarding your problem here - can you first try having just the print statement in the probe method to rule out any reflection related problems? If you still won't see the expected output, run BTrace in debug mode and/or collect the instrumented class files and attach the outputs to this issue.

Thanks!

@RoySunnySean007
Copy link
Author

Thanks Jaroslav Bachorik! I will have a try and provide feedback.

@jbachorik
Copy link
Collaborator

Any progress here?

@RoySunnySean007
Copy link
Author

Hi Jaroslav Bachorik,

Sorry for late...Will try and provide feedback.

Thanks,
Roy

@RoySunnySean007
Copy link
Author

Hi Jaroslav Bachorik,

Without reflection code, it can work. Regarding reflection part, let me do more test. Thanks for ur kindly guide.

Code:
import com.sun.btrace.annotations.;
import static com.sun.btrace.BTraceUtils.
;

@btrace
public class BHello {
@OnMethod(clazz = "+java.lang.Object", method = "")
public static void onNewThing(@self Object o, @ProbeClassName String pcn) {
print(pcn);
print('\t');
println(Strings.str(sizeof(o)));
}

}

Thanks,
Roy

@jbachorik
Copy link
Collaborator

Any updates on this?

@RoySunnySean007
Copy link
Author

Hi Jaroslav Bachorik,

Sorry for late due to other tasks...Will try and provide feedback.

Thanks,
Roy

@RoySunnySean007
Copy link
Author

Hi Jaroslav Bachorik,

I just tried Oracle JDK8, it can work with reflection. Actually we are using other JDK distributions, let me try it as well, maybe it is interim issue which can't reproduced. Thanks for ur kindly follow up.

BTrace code:

import com.sun.btrace.annotations.;
import static com.sun.btrace.BTraceUtils.
;

@btrace
public class BHello {
@OnMethod(clazz = "+java.lang.Object", method = "")
public static void onNewThing(@self Object o, @ProbeClassName String pcn) {
println("Roytest");
Class objectClass = Reflective.classOf(o);
String objectClassString = Reflective.name(objectClass);

    if (Strings.compareTo(pcn, objectClassString) == 0) {
        print(pcn);
        print('\t');
        println(Strings.str(sizeof(o)));

    }

}
}

Thanks,
Roy

@RoySunnySean007
Copy link
Author

Hi Jaroslav Bachorik,

I tried in our JDK distributions (JDK7), seems reflection can't work. Seems instrumented classes and probe output was not generated. Could u please help to have a check? Thx!

The following is debug message:

~/rzhang/BTrace/bin> ./btrace -v -o a.txt -d . 16343 BHello.java
DEBUG: outputFile is a.txt
DEBUG: dumpDir is .
DEBUG: assuming default port 2020
DEBUG: assuming default classpath '.'
DEBUG: compiling BHello.java
DEBUG: compiled BHello.java
DEBUG: attaching to 16343
DEBUG: checking port availability: 2020
DEBUG: attached to 16343
DEBUG: loading /export/home/sfuser/rzhang/BTrace/build/btrace-agent.jar
DEBUG: agent args: port=2020,statsd=,debug=true,dumpClasses=true,dumpDir=.,bootClassPath=.,systemClassPath=/usr/java/sapjvm_7.1.059/jre/../lib/tools.jar,probeDescPath=.
DEBUG: loaded /export/home/sfuser/rzhang/BTrace/build/btrace-agent.jar
DEBUG: registering shutdown hook
DEBUG: registering signal handler for SIGINT
DEBUG: submitting the BTrace program
DEBUG: opening socket to 2020
DEBUG: setting up client settings
DEBUG: sending instrument command: []
DEBUG: entering into command loop
DEBUG: received com.sun.btrace.comm.RenameCommand@5ba3f27a
DEBUG: received com.sun.btrace.comm.OkayCommand@74751b3
^CPlease enter your option:
1. exit
2. send an event
3. send a named event
4. flush console output
1
DEBUG: sending exit command
DEBUG: received com.sun.btrace.comm.ExitCommand@741a8937

Thanks,
Roy

@github-actions
Copy link

Stale issue message

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants