Is there a way to get monitoring on execution time per function?

How long a function takes to execute in preview doesn’t always match up to production usage in a Workshop application on real queries, is there a way (even a manual report) that allows a user to monitor the execution time per function?

I don’t believe there is currently (April 2024) a utility for viewing function execution times in-platform, however, depending on which aspect of Function execution duration you are interested in there may be an approach that works:

If your function is an OntologyEditFunction possible approach is to measure the real-world time between the start of your Function’s usercode, and the end of your code. You can do this like so:

@OntologyEditFunction()
public myFunction(): void {
    const startTime = Timestamp.now();

    // existing function logic

    const functionDurationInMillis = Timestamp.now() - startTime();
    const runLog = Objects.create().functionRunLog(Uuid.random()); // A brand-new object type to store run duration.
    runLog.durationMillis = functionDurationInMillis; // add any other metadata that is useful, i.e. objects loaded, size of LLM prompt
}

This approach could be useful for tracking the amount of time a computation-heavy function takes to execute on a range of real-world inputs, or when calling out to an LLM with AIP.

As noted, this only works for existing OntologyEditFunctions and can allow you to build up a history of the time it takes to execute the code within your function. This does not include the time spent preparing the Function’s execution, or the time it takes to apply the Action edits performed by the Function. By using restricted views, you may also be able to limit access to these “logs” to the user that executed the function and an admin user for a global view.

1 Like

As a side note: the time functions take to execute in preview is actually often larger than in production.

1 Like