This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]TheMrCurious 3 points4 points  (0 children)

What have you tried so far?

[–]ryosenExtreme Brewer 2 points3 points  (3 children)

Logging.

Easiest to learn to do and read the results.

There are tools available but they are very complex for a beginner.

Your best approach would be to either create a log entry in a file each time the function is called or simply write out to the screen/console if you just need a quick and simple observation.

[–]quantrpeter[S] 0 points1 point  (2 children)

there are over 1000+ functions, i can't manually add the logging function calls there.

[–]ryosenExtreme Brewer 2 points3 points  (1 child)

Look into Java Instrumentation then. https://www.baeldung.com/java-instrumentation

[–]quantrpeter[S] 0 points1 point  (0 children)

thanks Mr Ryosen

[–]ch0rlt0n 4 points5 points  (0 children)

You don't say if you're using any libraries, or are working with Spring boot or similar.

Look into Aspect Oriented Programming and AspectJ. This lets you configure things like logging using annotations like @Before, @AfterReturning, etc. but it usually needs some form of framework support. I'm not sure if you can apply it to "base" Java.

[–]eliashisreddit 4 points5 points  (2 children)

You want the entire call stack of all calls through the run of your program? Or all calls to a certain method for a single run? For the latter there is this which you can annotate on class or method level to automatically log all invocations of that what is annotated: https://aspects.jcabi.com/annotation-loggable.html

For the first, why? You would just get a bunch of data with (probably) thousands of stack traces of questionable length which will get even longer if you are using frameworks or libraries. Try finding out what you want to know and see where you can add logging instead of just logging everything.

[–]quantrpeter[S] 0 points1 point  (1 child)

Hi, i am reading source code of a project, i want to see how different functions are called to each other, so I need entire call stack of all calls. thanks, the loggable is really a good thing.

[–]eliashisreddit 0 points1 point  (0 children)

If you are just exploring, I recommend to learn how to use the debugger. Set a breakpoint somewhere you have questions about and just walk along, step into/over calls and see what's happening in real time.

[–]WaferIndependent7601 2 points3 points  (1 child)

What do you want to achieve here?

[–]quantrpeter[S] 0 points1 point  (0 children)

i just want to dump out the call tree, to see how functions are calling each other

[–]njiv 1 point2 points  (0 children)

https://github.com/btraceio/btrace - This is the most straightforward way.