Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build statistics to Log Manifest Entry, exact build duration #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Sources/XCLogParser/logmanifest/LogManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
return try parse(dictionary: logManifestDictionary, atPath: logManifestURL.path)
}

public func parse(dictionary: NSDictionary, atPath path: String) throws -> [LogManifestEntry] {

Check failure on line 35 in Sources/XCLogParser/logmanifest/LogManifest.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 43 lines (function_body_length)
guard let logs = dictionary["logs"] as? [String: [String: Any]] else {
throw LogError.invalidLogManifest("The file at \(path) is not a valid " +
"LogManifest file.")
Expand All @@ -46,24 +46,38 @@
let timeStartedRecording = entry.value["timeStartedRecording"] as? Double,
let timeStoppedRecording = entry.value["timeStoppedRecording"] as? Double,
let className = entry.value["className"] as? String,
let type = LogManifestEntryType.buildFromClassName(className)
let type = LogManifestEntryType.buildFromClassName(className),
let primaryObservable = entry.value["primaryObservable"] as? [String: Any],
let totalNumberOfAnalyzerIssues = primaryObservable["totalNumberOfAnalyzerIssues"] as? Int,
let totalNumberOfErrors = primaryObservable["totalNumberOfErrors"] as? Int,
let totalNumberOfWarnings = primaryObservable["totalNumberOfWarnings"] as? Int,
let totalNumberOfTestFailures = primaryObservable["totalNumberOfTestFailures"] as? Int,
let highLevelStatus = primaryObservable["highLevelStatus"] as? String
else {
throw LogError.invalidLogManifest("The file at \(path) is not a valid " +
"LogManifest file.")
}
let startDate = Date(timeIntervalSinceReferenceDate: timeStartedRecording)
let endDate = Date(timeIntervalSinceReferenceDate: timeStoppedRecording)
let timestampStart = Int(startDate.timeIntervalSince1970.rounded())
let timestampEnd = Int(endDate.timeIntervalSince1970.rounded())

let timestampStart = startDate.timeIntervalSince1970
let timestampEnd = endDate.timeIntervalSince1970
let statistics = LogManifestEntryStatistics(
totalNumberOfErrors: totalNumberOfErrors,
totalNumberOfAnalyzerIssues: totalNumberOfAnalyzerIssues,
highLevelStatus: highLevelStatus,
totalNumberOfTestFailures: totalNumberOfTestFailures,
totalNumberOfWarnings: totalNumberOfWarnings
)
return LogManifestEntry(uniqueIdentifier: uniqueIdentifier,
title: title,
scheme: scheme,
fileName: fileName,
timestampStart: timestampStart,
timestampEnd: timestampEnd,
duration: timestampEnd - timestampStart,
type: type)
type: type,
statistics: statistics
)
}.sorted(by: { lhs, rhs -> Bool in
return lhs.timestampStart > rhs.timestampStart
})
Expand Down
28 changes: 23 additions & 5 deletions Sources/XCLogParser/logmanifest/LogManifestModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
public let title: String
public let scheme: String
public let fileName: String
public let timestampStart: Int
public let timestampEnd: Int
public let duration: Int
public let timestampStart: TimeInterval
public let timestampEnd: TimeInterval
public let duration: Double
public let type: LogManifestEntryType

public let statistics: LogManifestEntryStatistics

Check failure on line 50 in Sources/XCLogParser/logmanifest/LogManifestModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
public init(uniqueIdentifier: String, title: String, scheme: String, fileName: String,
timestampStart: Int, timestampEnd: Int, duration: Int, type: LogManifestEntryType) {
timestampStart: TimeInterval, timestampEnd: TimeInterval, duration: Double, type: LogManifestEntryType, statistics: LogManifestEntryStatistics) {

Check failure on line 52 in Sources/XCLogParser/logmanifest/LogManifestModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less: currently 161 characters (line_length)
self.uniqueIdentifier = uniqueIdentifier
self.title = title
self.scheme = scheme
Expand All @@ -57,6 +58,23 @@
self.timestampEnd = timestampEnd
self.duration = duration
self.type = type
self.statistics = statistics
}

}

public struct LogManifestEntryStatistics: Encodable {
public let totalNumberOfErrors: Int
public let totalNumberOfAnalyzerIssues: Int
public let highLevelStatus: String
public let totalNumberOfTestFailures: Int
public let totalNumberOfWarnings: Int

Check failure on line 72 in Sources/XCLogParser/logmanifest/LogManifestModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)
public init(totalNumberOfErrors: Int, totalNumberOfAnalyzerIssues: Int, highLevelStatus: String, totalNumberOfTestFailures: Int, totalNumberOfWarnings: Int) {

Check failure on line 73 in Sources/XCLogParser/logmanifest/LogManifestModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less: currently 162 characters (line_length)
self.totalNumberOfErrors = totalNumberOfErrors
self.totalNumberOfAnalyzerIssues = totalNumberOfAnalyzerIssues
self.highLevelStatus = highLevelStatus
self.totalNumberOfTestFailures = totalNumberOfTestFailures
self.totalNumberOfWarnings = totalNumberOfWarnings
}
}
31 changes: 24 additions & 7 deletions Tests/XCLogParserTests/LogManifestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
<dict>
<key>highLevelStatus</key>
<string>W</string>
<key>totalNumberOfAnalyzerIssues</key>
<integer>0</integer>
<key>totalNumberOfErrors</key>
<integer>0</integer>
<key>totalNumberOfTestFailures</key>
<integer>0</integer>
<key>totalNumberOfWarnings</key>
<integer>2</integer>
</dict>
<key>schemeIdentifier-containerName</key>
<string>MyApp</string>
Expand Down Expand Up @@ -95,7 +103,13 @@
"documentTypeString": "&lt;nil&gt;",
"domainType": "Xcode.IDEActivityLogDomainType.BuildLog",
"fileName": "599BC5A8-5E6A-4C16-A71E-A8D6301BAC07.xcactivitylog",
"highLevelStatus": "E",
"primaryObservable": [
"highLevelStatus": "E",
"totalNumberOfErrors": 1,
"totalNumberOfAnalyzerIssues": 0,
"totalNumberOfTestFailures": 0,
"totalNumberOfWarnings": 2
],
"schemeIdentifier-containerName": "MyApp project",
"schemeIdentifier-schemeName": "MyApp",
"schemeIdentifier-sharedScheme": 1,
Expand All @@ -109,7 +123,13 @@
"documentTypeString": "&lt;nil&gt;",
"domainType": "Xcode.IDEActivityLogDomainType.BuildLog",
"fileName": "D1FEAFFA-2E88-4221-9CD2-AB607529381D.xcactivitylog",
"highLevelStatus": "E",
"primaryObservable": [
"highLevelStatus": "E",
"totalNumberOfErrors": 1,
"totalNumberOfAnalyzerIssues": 0,
"totalNumberOfTestFailures": 0,
"totalNumberOfWarnings": 2
],
"schemeIdentifier-containerName": "MyApp project",
"schemeIdentifier-schemeName": "MyApp",
"schemeIdentifier-sharedScheme": 1,
Expand All @@ -128,13 +148,10 @@
return
}


Check failure on line 151 in Tests/XCLogParserTests/LogManifestTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

Check failure on line 151 in Tests/XCLogParserTests/LogManifestTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Vertical Whitespace Violation: Limit vertical whitespace to a single empty line. Currently 2. (vertical_whitespace)
let startDate = Date(timeIntervalSinceReferenceDate: firstStartedRecording)
let endDate = Date(timeIntervalSinceReferenceDate: firstStoppedRecording)
let calendar = Calendar.current
guard let expectedDuration = calendar.dateComponents([.second], from: startDate, to: endDate).second else {
XCTFail("Error creating an expected duration field")
return
}
let expectedDuration = endDate.timeIntervalSince1970 - startDate.timeIntervalSince1970
XCTAssertEqual(expectedDuration, latestLog.duration)
}

Expand Down