A utility class to profile Apex
Before we begin to write our profiling utility, let’s think about what output we expect from this utility class. When it comes to profiling information, we can have the information output to the debug log for us to inspect, making the information transient—that is, it will only exist for the transaction and will not persist. There may also be a need for the output to be logged to a data store or collected by a third party for it to be used long-term or allow aggregation for analytics. We may also want this profiling utility to persist within our code so that we can turn it on and off in the future to allow us to debug errors that are due to governor limit exceptions. This could allow the utility to operate in tandem with the Logger
utility we discussed in Chapter 4, Exceptions and Exception Handling. We may also want the utility to allow us to check at runtime whether we are going to surpass a governor limit and block the action from occurring...