Thanks for getting in touch! Do you know about the full deployment logs? They give a bit more granular permissions.
If you look under RAW logs as the option - it should assist in timing for each part of the step.
Here is a doc image which shows where that toggle is: https://i.octopus.com/docs/images/3048147/3278094.png
Please let me know if that is what you were looking for.
The parsing code isn't something easily shared, there's quite a lot to it as it's used to get all the information about the deployment. When we were implementing the timing display UI feature we factored in total running time, what you're trying to determine is the core work of the step that's a bit more parsing effort.
I checked the API response it may have enough detail for what you want to calculate. But I suggest you double check for your deployments, if you go to the API route api/tasks/ServerTasks-<yourtasknumber>/details will return you a Task and it will have ActivityLogs, you'll see the LogElements array and it will have the entries, look for the script related ones like Deploying package or Making sure a Website or Executing script on and you can extract the OccurredAt times for those entries, and then subtract that time from the next step that starts after it, or if it's the last step then the time of The deployment completed successfully.
If you determine the API call data doesn't have enough detail and you really want to parse the server logs, don't use the raw ones returned form the UI as they are already processed to a human readable format. In the Server\Tasks\ logging folder where Octopus runs, pick the files for the deployments you do want to analyse.
The structure of each line is a comma delimited set of details.
["ServerTasks-2310_ABCDEF/STEP_LEVEL1_GUID/SECTION_GUID/ANOTHER_SECTION_GUID","INF","2017-05-25T13:11:52.6685530+00:00","Executing script on TEST","",0]
You'll want to make use of "INF" or "VBS" only (and not "PLN" entries as they are created up front on creation - well before deployment happens). Again you're looking for the lines that represent the real start and end of processing effort you want to measure.