Visualising the build process of your iOS app with XCLogParser
Another tool under your belt to keep you iOS app stable
Have you ever wondered why your build is going so slow? How can you make it faster? The first step is to understand what is going on in the build process and what’s holding your app build up. Xcode build logs doesn’t really tell the whole story and it can be hard to understand where the underlying problem is. So is there an alternative way for us to understand whats going on during the build process? Yes there is! XCLogParser to the rescue. XCLogParser can generate visual representations of an apps build log such that it is easier to understand and navigate.
This post will give you an introduction to the problem and how XCLogParser can solve it.
Please note this post won’t cover how to install XCLogParser. Please refer to the documentation on their Github README.
The problem
Whilst building an iOS app you can navigate to the report navigator and see text output of the steps the build system has taken for all of your various required targets; this is a build log.
You can find the build log file usually in your derived data path with extension xcactivitylog
under {DERIVED_DATA_PATH}/{YOUR_PROJECT}-{SOME_RANDOM_IDENTIFIER}/Logs/Build/{FILENAME}.xcactivitylog
.
The format of this file is known as SLF format. A format not readable by humans and many applications other than Xcode and Apple tools itself. Whilst information displayed in the Xcode report is helpful, the text-heavy format can make it hard to disseminate information and extract insights from. Just like a lot of rows full of numbers in an excel sheet without a graph.
The solution
This is where XCLogParser comes to the rescue.
XCLogParser is a tool that can parse xcactivitylog
and generate a variety of different reports such as human readable JSON but also it is able to generate HTML reports with graphical visualisation of the build process.
Generating HTML reports using XCLogParser
To generate the HTML report as shown above simply run the following command at the root of your project:
xclogparser parse --xcodeproj <YOUR_XCODEPROJ_FILENAME>.xcodeproj --reporter html
However if you want you can generate the report from whever you want by specifying the file using the --file
argument instead of the --xcodeproj
argument. Remember you can find this file in your derived data. For example:
xclogparser parse --file <PATH_TO_DERVIVED_DATA>/<PROJECT_NAME>-<SOME_RANDOM_ID>/Logs/Build/<RANDOM_ID>.xcactivitylog --reporter html
Generating JSON reports using XCLogParser
In some scenarios you may want to track certain aspects of your project over time. For example you may want to track build times. You can create a JSON format report which is easier to consume and create custom visualisations from by using the json
value for the argument --reporter
. These can generate very details build logs in json format. However you can also generate just a summary using the summaryJson
value instead.
Below you can find a summary json:
{
"parentIdentifier" : "",
"fetchedFromCache" : false,
"title" : "Build xclogparsertest",
"warningCount" : 0,
"duration" : 3.2450469732284546,
"startTimestamp" : 1700841915.0000801,
"signature" : "Build xclogparsertest",
"errors" : [
],
"compilationEndTimestamp" : 1700841915.5918541,
"compilationDuration" : 0.59177398681640625,
"endDate" : "2023-11-24T16:05:18.245000Z",
"errorCount" : 0,
"domain" : "Xcode.IDEActivityLogDomainType.BuildLog",
"type" : "main",
"identifier" : "<KMACHINE_NAME>_87E84819-AAA7-43C4-8EEE-34956F36A365_1",
"buildStatus" : "succeeded",
"schema" : "xclogparsertest",
"subSteps" : [
],
"endTimestamp" : 1700841918.245127,
"architecture" : "",
"machineName" : "<KMACHINE_NAME>",
"buildIdentifier" : "<KMACHINE_NAME>_87E84819-AAA7-43C4-8EEE-34956F36A365",
"startDate" : "2023-11-24T16:05:15.000000Z",
"warnings" : [
],
"notes" : [
],
"documentURL" : "",
"detailStepType" : "none"
}
Summary
Before diving into build time optimisations it’s good to understand where the time compilation bottlenecks are produced. This is where XCLogParser can aid on your mission to keep build time low by either visualising your build processes or having them tracked by producing a json report.