Skip to content

Commit

Permalink
Logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cuba committed Mar 30, 2024
1 parent 66887e7 commit 4baeedc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,17 @@ import os
for files: [AdBlockEngineManager.FileInfo],
resourcesInfo: GroupedAdBlockEngine.ResourcesInfo?
) async throws {
let infosString = files.map({ " \($0.filterListInfo.debugDescription)" })
.joined(separator: "\n")
let count = files.count

ContentBlockerManager.log.debug(
"Compiling `\(self.cacheFolderName)` engine from \(count) sources:\n\(infosString)"
)

let engineType = self.engineType
let group = try combineRules(for: files)
self.pendingGroup = group

ContentBlockerManager.log.debug(
"""
Compiling `\(self.cacheFolderName)` engine from \(group.infos.count) sources:
\(group.debugDescription)"
"""
)

// 2. Compile the engine
let groupedEngine = try await Task.detached(priority: .high) {
let engine = try GroupedAdBlockEngine.compile(group: group, type: engineType)
Expand All @@ -270,11 +269,12 @@ import os
}

private func set(engine: GroupedAdBlockEngine) {
let infosString = engine.group.infos.map({ " \($0.debugDescription)" }).joined(separator: "\n")
let fileTypeString = engine.group.fileType.debugDescription
let count = engine.group.infos.count
let group = engine.group
ContentBlockerManager.log.debug(
"Set `\(self.cacheFolderName)` (\(fileTypeString)) engine from \(count) sources:\n\(infosString)"
"""
Set `\(self.cacheFolderName)` (\(group.fileType.debugDescription)) engine from \(group.infos.count) sources:
\(group.debugDescription)"
"""
)
self.engine = engine
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BraveCore
import Data
import Foundation
import Preferences
import os
import os.log

/// An object that wraps around an `AdblockEngine` and caches some results
/// and ensures information is always returned on the correct thread on the engine.
Expand All @@ -18,8 +18,8 @@ public actor GroupedAdBlockEngine {

public var debugDescription: String {
switch self {
case .filterList(let componentId, _): return "filterList(\(componentId))"
case .filterListURL(let uuid): return "filterListURL(\(uuid))"
case .filterList(let componentId, _): return componentId
case .filterListURL(let uuid): return uuid
}
}
}
Expand All @@ -35,7 +35,7 @@ public actor GroupedAdBlockEngine {
}
}

public enum EngineType: Hashable, CaseIterable {
public enum EngineType: Hashable, CaseIterable, CustomDebugStringConvertible {
case standard
case aggressive

Expand All @@ -45,6 +45,13 @@ public actor GroupedAdBlockEngine {
case .aggressive: return true
}
}

public var debugDescription: String {
switch self {
case .aggressive: return "aggressive"
case .standard: return "standard"
}
}
}

public struct FilterListInfo: Codable, Hashable, Equatable, CustomDebugStringConvertible {
Expand All @@ -62,7 +69,9 @@ public actor GroupedAdBlockEngine {
let fileType: GroupedAdBlockEngine.FileType

public var debugDescription: String {
return infos.map({ $0.debugDescription }).joined(separator: ", ")
return infos.enumerated()
.map({ " #\($0) \($1.debugDescription)" })
.joined(separator: "\n")
}
}

Expand Down Expand Up @@ -207,7 +216,7 @@ public actor GroupedAdBlockEngine {
let state = Self.signpost.beginInterval(
"compileEngine",
id: signpostID,
"\(group.debugDescription)"
"\(type.debugDescription) (\(group.fileType.debugDescription)): \(group.debugDescription)"
)

do {
Expand Down

0 comments on commit 4baeedc

Please sign in to comment.