How is profiling different from logging?
Is it just that profiling is used for performance measurements to see how long each function takes? Or am I off?
Typically, how are profiling libraries used?
What types of stats are obtained by profiling?
Logging tells you what happened. It's great for forensics and debugging.
Profiling quantifies that: it tells you how much time your code spent in each area, or how many times a body of code was executed. It helps you improve your code's performance.
Profiling typically operates at the level of a line of code, a function call, or sometimes a file. For each level, it can typically tell you:
How many times the unit was executed. It's generally less important to optimize rarely-used code than code that executes millions of times. One exception is code that makes a user (or another process) wait for it to complete.
How many times a branch was taken, say in an if
or switch
statement. Again, you typically care most about optimizing often-used code.
How much time was spent in a particular function. Warning: even experienced developers are often surprised by these results. It's very difficult to predict where your "time sinks" are.
How much time was spent in a function and all functions called within that function. Maybe it's not the function itself, but its children, that need optimizing.
How many times the unit was called by each caller. You may find that a particular function is called primarily from an unexpected place.
Armed with the data from a good profiler, you can often gain significant improvements in performance with relatively little effort.
Profiling is about determining performance with respect to function/method calls, e.g.
The whole idea of profiling is getting a good overview of a system to determine where optimisations can be made. If you know a particular function is called 20 more times than the 2nd most highly called function, you know when to focus your optimisation efforts.
It also shows you where not to spend your time. You don't want to spend a day optimising a function that is only called once per hour. You want to focus your time on optimising those functions that are called multiple times per second.
Logging, in my understanding, is just keeping track of what has been called (but without the detailed metadata associated with each call).
Profiling libraries such as Rational Quantify work by instrumenting the code to gather statistics as it is running. This will have an implicit performance impact, but it will be relative across the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With