-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathCompileMeasure.swift
More file actions
executable file
·93 lines (73 loc) · 2.51 KB
/
CompileMeasure.swift
File metadata and controls
executable file
·93 lines (73 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// CompileMeasure.swift
// BuildTimeAnalyzer
//
import Foundation
@objcMembers class CompileMeasure: NSObject {
dynamic var time: Double
var path: String
var code: String
dynamic var filename: String
var references: Int
private var locationArray: [Int]
public enum Order: String {
case filename
case time
}
var fileAndLine: String {
return "\(filename):\(locationArray[0])"
}
var fileInfo: String {
return "\(fileAndLine):\(locationArray[1])"
}
var location: Int {
return locationArray[0]
}
var timeString: String {
return String(format: "%.1fms", time)
}
init?(time: Double, rawPath: String, code: String, references: Int) {
let untrimmedFilename = rawPath.split(separator: "/").map(String.init).last
guard let filepath = rawPath.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.split(separator: ":").map(String.init).first else { return nil }
let locationString = String(rawPath[filepath.endIndex...].dropFirst())
let locations = locationString.split(separator: ":").compactMap{ Int(String.init($0)) }
guard locations.count == 2 else { return nil }
self.time = time
self.code = code
self.path = filepath
self.filename = filename
self.locationArray = locations
self.references = references
}
init?(rawPath: String, time: Double) {
let untrimmedFilename = rawPath.split(separator: "/").map(String.init).last
guard let filepath = rawPath.split(separator: ":").map(String.init).first,
let filename = untrimmedFilename?.split(separator: ":").map(String.init).first else { return nil }
self.time = time
self.code = ""
self.path = filepath
self.filename = filename
self.locationArray = [1,1]
self.references = 1
}
subscript(column: Int) -> String {
switch column {
case 0:
return timeString
case 1:
return fileInfo
case 2:
return "\(references)"
default:
return code
}
}
}
extension CompileMeasure: CSVExportable {
static var csvHeaderLine: String = ["time", "file", "references", "code"].joinedAsCSVLine(delimiter: .doubleQuote)
var csvLine: String
{
return [timeString, fileInfo, "\(references)", code].joinedAsCSVLine(delimiter: .doubleQuote)
}
}