Profiling / Get current method name

12 views
Skip to first unread message

nickk...@gmail.com

unread,
Apr 30, 2017, 7:13:46 PM4/30/17
to CodenameOne Discussions
I've recently had a significant performance issue come up and the cause was in my own code but took a bit of tracking down as it only happened on devices (and was much more severe on iOS devices).

The only way I could track it down was to put in a lot of logging statements throughout the code and track the timestamps to see which methods were taking a long time and narrow it down like that. Then removing all the log statements as there is no LogLevel (as far as I know) and I didn't want all that logging in a production build.

Also with no logs from newer iOS devices I had to run on an older device where I can get logs and hope that it was the same issue (it was).

I then thought about making a simple profiler based on this process that could be turned on and off with flags in order to mark sections of code that need this kind of work. In order to make it more useful than log statements though it would need to be easy to put into methods without a lot of boilerplate or strings. I thought of annotations but they need reflection if they are used at runtime and they can't modify the code significantly enough at compile time without significant changes to the structure of the classes.

So then I thought about marking the start and end of methods using new Throwable().getStackTrace() which returns an array of StackTraceElements and I can get the current method from that but its not implemented in CN1. Throwable.printStackTrace outputs directly to the standard error stream so I can't manipulate that either.

Its looking impossible due to the missing methods and no reflection - but here is what I'm trying to solve and how I'm thinking of doing it:

1. I would prefer not to have to get source and build from source, the beauty of CN1 is the build server and this process is a pain.
2. I would like this to show slow spots on the device, the performance monitor or NetBeans profiling tools on the simulator are no good, this particular issue didn't show on those at all and showed significantly on iOS devices (3000ms+ delay).
3. I would like to be able to see logs from newer iOS devices but that's a different issue.
4. Outputs either to the logs or to a file (or email) that I can analyse later.


Completely automated would be great but I can't think of anyway to do this without reflection so marking methods is fine if its a simple as possible:

public void doStuff() {
 
Profile.start();
 
//Do some things in here
Profile.stop();
}

I would like Profile.start() and Profile.stop() to automatically know which method they are being called from, otherwise I'm reliant on providing those as strings which is not safe from refactoring or misspelling and just adds more complexity.

Any suggestions here? Is there a way that we can get the method name? Barking up the wrong tree? 

Cheers,
Nick

Shai Almog

unread,
May 1, 2017, 1:07:15 AM5/1/17
to CodenameOne Discussions
We just use the standard iOS profiler which is really effective. I use the CPU time mode and it does show the CPU usage in percentage for every method in a graph hierarchy.
Reply all
Reply to author
Forward
0 new messages