This is a library to allow us to use the Chrome Tracing utility for apps script profiling. I've implemented a subset of what can be profiled, but will implement additional capabilities if there is enough interest. The VBA version is here - Chrome Tracing class for VBA
You'll need the ChromeTrace library which you can get on github or see below for the script project details. The code for the following tests is also available here on github.
It uses the Drive API - specifically my Drive JSON API for apps script - to create the Chrome Tracing file on drive. This means that you need to enable the Drive API from the Advanced services menu and the Cloud console.
Let's get straight down to an example. We'd like to see how long it takes to execute this snippet
Create a trace object
Run the code
Dump the results to drive in the given folder
Load to Chrome tracer and see the viz
And click on the bar and see the data
Now let's compare a couple of different traces
Here's the code that generated that
That's timing - now here's how to show values over time. This time we'll do the same thing, but also show a couple of values for each loop iteration. What we're looking at here are the two counts with each of the values as well as the timings for each section.
Picking a point in time, we can look at those values at that point
Here's the code for this
The Chrome tracing utility is rich with options. I won't cover them all here - just try it and play with it. It's very very good.
Although I'm not using the Apps Script Drive service, but rather the generic Drive API, the simplest way to get a properly scoped access token is to pretend that we're going to use the Drive service. To do that
If you do those things, then you'll get an appropriate authentication dialog that creates the needed scope - then your script access token can be passed over to the library when you create the ChromeTrace object. Alternatively you can use my cEzyOauth2 library, but that's a lot more complicated.
Covered in tracing
For help and more information join our community, follow the blog, follow me on twitter, or follow me on g+. If you have any additional Chrome tracing types activated, please let me know.
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > chrome > tracing >