From e4c6a4ebfa005743d6e6599d6f3d5006a559ffe5 Mon Sep 17 00:00:00 2001 From: Alec Miller Date: Mon, 18 Mar 2024 10:31:22 -0700 Subject: [PATCH] kram-profile - fix reload of raw file data --- kram-profile/kram-profile/File.swift | 40 +++++++++++++------ .../kram-profile/kram_profileApp.swift | 6 +++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/kram-profile/kram-profile/File.swift b/kram-profile/kram-profile/File.swift index 7b0995c..5f12291 100644 --- a/kram-profile/kram-profile/File.swift +++ b/kram-profile/kram-profile/File.swift @@ -132,6 +132,25 @@ class File: Identifiable, Hashable, Equatable, Comparable return modStamp != loadStamp } + public func eraseFileContent() { + loadStamp = nil + fileContent = nil + } + + public func eraseCaches() { + duration = 0.0 + + if fileType == .Build { + // for build fileType + buildTimings.removeAll() + buildStats = nil + } + else if fileType == .Memory { + // for memory fileType + threadInfo.removeAll() + } + } + public static func fileModificationDate(url: URL) -> Date? { do { let attr = try FileManager.default.attributesOfItem(atPath: url.path) @@ -241,6 +260,11 @@ func lookupFile(url: URL) -> File { // This wipes the duration, so it can be recomputed // TODO: may want to check crc32 if present before wiping all data + if file.archive == nil { + file.eraseFileContent() + file.eraseCaches() + } + fileCache[file.url] = file return file @@ -342,8 +366,7 @@ func lookupArchive(_ url: URL) -> Archive { if !isNewEntryMissing && (oldEntry.crc32 == newEntry.crc32) { // erase fileContent since it may alias mmap going away - file.loadStamp = nil - file.fileContent = nil + file.eraseFileContent() // keep any caches } @@ -352,17 +375,8 @@ func lookupArchive(_ url: URL) -> Archive { file.loadStamp = nil file.fileContent = nil - file.duration = 0.0 - - if file.fileType == .Build { - // for build fileType - file.buildTimings.removeAll() - file.buildStats = nil - } - else if file.fileType == .Memory { - // for memory fileType - file.threadInfo.removeAll() - } + file.eraseFileContent() + file.eraseCaches() } } } diff --git a/kram-profile/kram-profile/kram_profileApp.swift b/kram-profile/kram-profile/kram_profileApp.swift index 82ac214..a6ce85c 100644 --- a/kram-profile/kram-profile/kram_profileApp.swift +++ b/kram-profile/kram-profile/kram_profileApp.swift @@ -55,6 +55,9 @@ import UniformTypeIdentifiers // TODO: save/load the duration and modstamps for File at quit, and any other metadata (totals per section) // TODO: add jump to source/header, but path would need to be correct (sandbox block?) +// TODO: look into fast crc32 ops on M1 +// https://dougallj.wordpress.com/2022/05/22/faster-crc32-on-the-apple-m1/ + // Build traces // DONE: OptFunction needs demangled. All backend strings are still mangled. // Don’t need the library CBA uses just use api::__cxa_demangle() on macOS. @@ -542,6 +545,8 @@ func filenameToTimeRange(_ filename: String) -> TimeRange { case .Unknown: duration = 1.0 } + duration = 10.0 + return TimeRange(timeStart:0.0, timeEnd:duration) } @@ -566,6 +571,7 @@ func buildTimeRangeJson(_ timeRange:TimeRange) -> String? { let script = """ var objTime = { perfetto:{ + keepApiOpen: true, timeStart:\(timeStartInt)n, timeEnd:\(timeEndInt)n, viewPercentage:\(timeRange.viewPercentage)