Skip to content

Commit

Permalink
kram-profile - fix reload of raw file data
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Mar 18, 2024
1 parent 3d436f9 commit e4c6a4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
40 changes: 27 additions & 13 deletions kram-profile/kram-profile/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions kram-profile/kram-profile/kram_profileApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -542,6 +545,8 @@ func filenameToTimeRange(_ filename: String) -> TimeRange {
case .Unknown: duration = 1.0
}

duration = 10.0

return TimeRange(timeStart:0.0, timeEnd:duration)
}

Expand All @@ -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)
Expand Down

0 comments on commit e4c6a4e

Please sign in to comment.