Skip to content

Commit

Permalink
Adding pixel info for compilation perf metrics, changing compile resu…
Browse files Browse the repository at this point in the history
…lt into a struct
  • Loading branch information
studiosutara committed Dec 5, 2024
1 parent 8c2d168 commit 44ce600
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public enum ContentBlockerDebugEvents {

case contentBlockingCompilationFailed(listName: String, component: Component)

case contentBlockingCompilationTime

case contentBlockingLookupRulesSucceeded
case contentBlockingFetchLRCSucceeded
case contentBlockingLRCMissing
case contentBlockingNoMatchInLRC
case contentBlockingCompilationTaskPerformance(retryCount: Int, timeBucketAggregation: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public class ContentBlockerRulesManager: CompiledRuleListsSource {
}

private func startCompilationProcess() {
Logger.contentBlocking.debug("Starting compilataion process")
prepareSourceManagers()

// Prepare compilation tasks based on the sources
Expand Down Expand Up @@ -387,12 +386,14 @@ public class ContentBlockerRulesManager: CompiledRuleListsSource {
unprotectedSitesHash: nil))
}


// if let compilationTime = result.compilationTime {
//
// // todo: need to change this to the updated format with time range and iteration
// self.errorReporting?.fire(.contentBlockingCompilationTime, parameters: ["compilationTime": String(compilationTime)])
// }
// todo - this hard code is a placeholder till I figure out how to check for this task vs. Ad attr task
if task.rulesList.name == "TrackerDataSet" {
if let perfInfo = result.performanceInfo {
self.errorReporting?.fire(.contentBlockingCompilationTaskPerformance(retryCount: perfInfo.iterationCount,
timeBucketAggregation: perfInfo.compilationTime),
parameters: ["compilationTime": String(perfInfo.compilationTime)])
}
}

changes[task.rulesList.name] = diff
return rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ extension ContentBlockerRulesManager {
let compiledRulesList: WKContentRuleList
let model: ContentBlockerRulesSourceModel
let resultType: ResultType
let performanceInfo: PerformanceInfo?
let performanceInfo: PerformanceInfo?

struct PerformanceInfo {
let compilationTime: TimeInterval?
let iterationCount: Int?
let compilationTime: TimeInterval
let iterationCount: Int

// if none of the sources are broken, we do a minimum of one iteration which should be successful
init(compilationTime: TimeInterval, iterationCount: Int = 1) {
self.compilationTime = compilationTime
self.iterationCount = iterationCount
}
}

Check failure on line 43 in Sources/BrowserServicesKit/ContentBlocking/ContentBlockingRulesCompilationTask.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
enum ResultType {
Expand Down Expand Up @@ -178,19 +184,24 @@ extension ContentBlockerRulesManager {
func getCompilationResult(ruleList: WKContentRuleList,
model: ContentBlockerRulesSourceModel,
resultType: CompilationResult.ResultType) -> CompilationResult {
let compilationTime = self.compilationStartTime.map { start in CACurrentMediaTime() - start }
let perfInfo = CompilationResult.PerformanceInfo(compilationTime: compilationTime, iterationCount: getCompilationIterationCount())
let compilationTime = self.compilationStartTime.map { CACurrentMediaTime() - $0 }

let perfInfo = compilationTime.map {
CompilationResult.PerformanceInfo(compilationTime: $0,
iterationCount: getCompilationRetryCount())
}

return CompilationResult(compiledRulesList: ruleList,
model: model,
resultType: resultType,
performanceInfo: perfInfo)

Check failure on line 198 in Sources/BrowserServicesKit/ContentBlocking/ContentBlockingRulesCompilationTask.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
}
func getCompilationIterationCount() -> Int {

func getCompilationRetryCount() -> Int {
guard let brokenSources = sourceManager.brokenSources else {
return 0
// if none of the sources are broken, we do a minimum of one iteration which should be successful
return 1
}

Check failure on line 206 in Sources/BrowserServicesKit/ContentBlocking/ContentBlockingRulesCompilationTask.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
let identifiers = [
Expand All @@ -200,7 +211,8 @@ extension ContentBlockerRulesManager {
brokenSources.tdsIdentifier
]

return identifiers.compactMap { $0 }.count
// add 1 to account for the first iteration before we retry with any broken sources
return (identifiers.compactMap { $0 }.count) + 1
}

}
Expand Down

0 comments on commit 44ce600

Please sign in to comment.