深入解析XCLogParser的JSON日志格式

深入解析XCLogParser的JSON日志格式

XCLogParser Tool to parse Xcode and xcodebuild logs stored in the xcactivitylog format XCLogParser 项目地址: https://gitcode.com/gh_mirrors/xc/XCLogParser

XCLogParser是一个强大的工具,用于解析和分析Xcode构建日志。本文将详细介绍其JSON输出格式,帮助开发者更好地理解构建过程中的各个细节。

JSON日志结构概述

XCLogParser将Xcode构建过程解析为结构化的JSON数据,每个构建步骤都包含丰富的元数据。以下是一个典型的Swift文件编译步骤的JSON示例:

{
    "detailStepType": "swiftCompilation",
    "startTimestamp": 1545143336.649699,
    "endTimestamp": 1545143336.649699,
    "schema": "MyApp",
    "domain": "com.apple.dt.IDE.BuildLogSection",
    "parentIdentifier": "095709ba230e4eda80ab43be3b68f99c_1545299644.4805899_20",
    "endDate": "2018-12-18T14:28:56.650000+0000",
    "title": "Compile /Users/<redacted>/projects/MyApp/Libraries/Utilities/Sources/Disposables/Cancelable.swift",
    "identifier": "095709ba230e4eda80ab43be3b68f99c_1545299644.4805899_185",
    "signature": "CompileSwift normal x86_64 /Users/<redacted>/MyApp/Libraries/Utilities/Sources/Disposables/Cancelable.swift",
    "type": "detail",
    "buildStatus": "succeeded",
    "subSteps": [],
    "startDate": "2018-12-18T14:28:56.650000+0000",
    "buildIdentifier": "095709ba230e4eda80ab43be3b68f99c_1545299644.4805899",
    "machineName": "095709ba230e4eda80ab43be3b68f99c",
    "duration": 5.5941859483718872,
    "errorCount": 0,
    "warningCount": 0,
    "errors": [],
    "warnings": [],
    "fetchedFromCache": false,
    "compilationEndTimestamp": 1545143336.649699,
    "compilationDuration": 5.5941859483718872,
    "swiftFunctionTimes": [
        {
          "durationMS": 0.08,
          "occurrences": 5,
          "startingColumn": 36,
          "startingLine": 48,
          "file": "file:///Users/<redacted>/MyApp/Libraries/Utilities/Sources/Disposables/Cancelable.swift",
          "signature": "getter description"
        }
    ],
    "swiftTypeCheckTimes": [
        {
          "durationMS": 0.5,
          "occurrences": 2,
          "startingColumn": 16,
          "startingLine": 9,
          "file": "file:///Users/<redacted>/MyApp/Libraries/Utilities/Sources/Disposables/Cancelable.swift",
        }
    ]
}

构建步骤类型解析

JSON中的type字段标识了构建步骤的类型,主要有三种:

  1. main类型:整个构建过程的摘要,通常是构建的Xcode scheme
  2. target类型:属于main类型的构建目标
  3. detail类型:目标内部的详细步骤,如预构建阶段运行的脚本、单个文件的编译或其他构建规则

关键字段详解

基础信息字段

  • buildIdentifier:构建的唯一标识符,由机器名和IDEActivityLog的唯一标识符组成,确保在不同主机上的唯一性
  • duration:步骤执行时间(秒)
  • subSteps:属于当前步骤的子步骤数组
  • parentIdentifier:当前步骤所属的父步骤标识符
  • schema:运行的scheme名称
  • buildStatus:构建状态,值为succeededfailed
  • machineName:主机名,优先使用参数machine_name,否则使用系统返回的主机名

编译相关字段

  • signature:对于detail类型的步骤,包含实际执行的命令
  • detailStepType:仅detail类型步骤有,显示该步骤运行的内容
  • warningCount/errorCount:编译器产生的警告/错误数量
  • warnings/errors:警告/错误的详细列表
  • fetchedFromCache:指示文件是否从Xcode内部缓存获取

高级编译指标

  • compilationEndTimestamp:实际编译完成的时间戳(可能与整体步骤结束时间不同)
  • compilationDuration:仅编译阶段的实际持续时间
  • swiftFunctionTimes:Swift函数编译时间详情(需启用-debug-time-function-bodies标志)
  • swiftTypeCheckTimes:Swift类型检查时间详情(需启用-debug-time-expression-type-checking标志)

构建步骤类型识别

XCLogParser会解析detail步骤的signature内容来确定其类型,便于数据聚合。以下是可能的类型及其描述:

| 类型值 | 描述 | |--------|------| | cCompilation | Objective-C、C或C++文件编译 | | swiftCompilation | Swift文件编译 | | scriptExecution | 构建阶段脚本执行 | | createStaticLibrary | 使用Libtool创建静态库 | | linker | 链接器运行 | | copySwiftLibs | 复制Swift运行时库 | | compileAssetsCatalog | 编译Assets目录 | | compileStoryboard | 编译Storyboard文件 | | writeAuxiliaryFile | 复制辅助文件到派生数据 | | linkStoryboards | Storyboard链接 | | copyResourceFile | 复制资源文件 | | mergeSwiftModule | 执行合并Swift模块工具 | | XIBCompilation | 编译XIB文件 | | swiftAggregatedCompilation | 聚合Swift编译 | | precompileBridgingHeader | 预编译桥接头文件 | | other | 上述类型之外 | | none | 非detail类型的步骤 |

实际应用建议

  1. 构建优化:通过分析swiftFunctionTimesswiftTypeCheckTimes,可以识别编译时间过长的函数,进行针对性优化
  2. 缓存利用fetchedFromCache字段帮助了解缓存命中情况,优化构建系统配置
  3. 问题定位:结合errorswarnings字段,快速定位构建失败原因
  4. 性能分析:比较compilationDurationduration,了解构建过程中非编译阶段的时间消耗

通过深入理解XCLogParser的JSON输出格式,开发者可以更有效地分析构建过程,优化构建性能,提升开发效率。

XCLogParser Tool to parse Xcode and xcodebuild logs stored in the xcactivitylog format XCLogParser 项目地址: https://gitcode.com/gh_mirrors/xc/XCLogParser

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

朱焰菲Wesley

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值