writing probe for getting function arguments and return

Questions about YourKit Java Profiler
Post Reply
sherkat
Posts: 6
Joined: Sun Dec 25, 2022 9:06 am

writing probe for getting function arguments and return

Post by sherkat »

hi all

i want to get passed args and return value of all invoked methods. i couldn't find any built-in options to do this.
i suppose the only way is to write a custom probe.
can anyone show me a code snippet of doing this?
Anton Katilin
Posts: 6154
Joined: Wed Aug 11, 2004 8:37 am
Contact:

Re: writing probe for getting function arguments and return

Post by Anton Katilin »

Hi,

Please try using triggers:
https://www.yourkit.com/docs/java/help/triggers.jsp

Add a trigger on method invocation with an action such as "Print Message Invocation Detail" to log to a file or console or "Record Method Invocation" to add events visible in the profiler results.
sherkat
Posts: 6
Joined: Sun Dec 25, 2022 9:06 am

Re: writing probe for getting function arguments and return

Post by sherkat »

done exactly like the link but im not getting anything; not in the log nor in the YKJP.
im using attach mode
by log i mean the file in the ".yjp\log" folder
Anton Katilin
Posts: 6154
Joined: Wed Aug 11, 2004 8:37 am
Contact:

Re: writing probe for getting function arguments and return

Post by Anton Katilin »

Please see the actions which I recommended. They use macros which define what kind of detail is to be logged. The Print* actions allow you to choose the target file.

The simplest way to play with triggers is to connect to a profiled application and compose triggers via the user interface (add trigger, add action) as shown in the help page. You can apply the changes immediately.

You can later export the trigger description to reuse it or apply on start.
sherkat
Posts: 6
Joined: Sun Dec 25, 2022 9:06 am

Re: writing probe for getting function arguments and return

Post by sherkat »

i did as you told:
Image

anything that I'm doing wrong?
Anton Katilin
Posts: 6154
Joined: Wed Aug 11, 2004 8:37 am
Contact:

Re: writing probe for getting function arguments and return

Post by Anton Katilin »

Sorry I cannot see the image.
Anton Katilin
Posts: 6154
Joined: Wed Aug 11, 2004 8:37 am
Contact:

Re: writing probe for getting function arguments and return

Post by Anton Katilin »

Please specify appropriate method name pattern instead of the placeholder in the trigger properties - see the top node shown on the screenshot you provided.

You have "agentlog" specified. The output will be written to the agent log file <user home>/.yjp/log/<name>-<pid>.log. Please see the other options above the field e.g. to explicitly specify the output file name.
sherkat
Posts: 6
Joined: Sun Dec 25, 2022 9:06 am

Re: writing probe for getting function arguments and return

Post by sherkat »

i know it was a stupid noob question and thanks for coping with that.
now I'm seeing the results in the log file.
sherkat
Posts: 6
Joined: Sun Dec 25, 2022 9:06 am

Re: writing probe for getting function arguments and return

Post by sherkat »

btw,

im getting this with {@params} :

Code: Select all

22.9-166 4.402: Entering: MyTest:main(java.lang.String[])
  this: MyTest
  params:
    [Ljava.lang.String;@6767c1fc
  
is there a way to log the array's contents too?(or content of custom objects)
Anton Katilin
Posts: 6154
Joined: Wed Aug 11, 2004 8:37 am
Contact:

Re: writing probe for getting function arguments and return

Post by Anton Katilin »

Currently this is not possible via a trigger. You should write a custom probe for more sophisticated parameter processing.
Post Reply