How to add code to every method in a project automatically

What’s the fastest way to add 2 lines of (constant/identical/not variable) code to every existing method in a project?

What I’m trying to do is log the completion time of every method to find offending code that’s slowing down my app, so this code just adds a methodname and date to a listbox.

Is there something like a MethodComplete function that belongs to the app that could do this instead of having to add code at the end of every method?

Thanks in advance!

Don’t put 2 lines of code throughout your project. Put that code in a global module and call that. Much more maintainable. But AFAIK, you’ll have to visit every method and place the call to your global method.

And how about simply profiling your code? Isn’t that enough information?

I’d start with the built-in Code Profiler.

There is no fast way to do what you describe in the IDE. If you are comfortable hacking up project files, you can do what you are describing using a combination of command line tools and other text editors… but if all you are trying to do is figure out where the expensive parts of your code are learn about and use the profiler.

Add the constant to a module and make it global. No need to replicate in every method, it is a waste.

@Paul Lefebvre I checked the Profile Code menu item, ran the project, accessed the part of the project with the expensive code, hit the stop button in the IDE. Unfortunately, no Profile section appears in the Navigator of the IDE. I restarted Xojo and still can’t get the Profile section to appear. I don’t see any other steps here : Any thoughts?

You have to let your debug build quit normally. Start it up, run the code in question, quit, and the Profile data will appear.

@Kem Tekinay That worked!

It’s not a constant, it is constant non-changing code that he needs to have in every method and event.

Usage scenarios include (among others):

Speed profiling
Logging code execution order
Exception handling

In the big red box on the Code Profiler page:

@Markus Winter Yes, and I’m open to other ways to debug compiled webapps, but if there is no obvious expensive code seen in the Profiler when profiling the app locally, but sections of the app still bog down in the compiled version on the webserver, I’m not sure of another way to track down expensive compiled webapp code, aside from adding code to every method to log it’s execution completion time, etc.

@Paul Lefebvre Ah yes, I see that caveat box now :slight_smile:

I see that Code Profiler works on compiled webapps too - great news! As a number of you stated, that may fully take care of my debugging needs.