Skip to content

Commit

Permalink
kram-profile - split update from lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Mar 18, 2024
1 parent 49dacbe commit ac02908
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 16 additions & 5 deletions kram-profile/kram-profile/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ class File: Identifiable, Hashable, Equatable, Comparable
}

public func eraseFileContent() {
loadStamp = nil
// fileContent should get reloaded
fileContent = nil

// Perfetto should reload the fileContent
loadStamp = nil
}

public func eraseCaches() {
Expand Down Expand Up @@ -245,7 +248,7 @@ var droppedFileCache : [URL] = []
// Flattened list of supported files from folders and archives
var fileCache : [URL:File] = [:]

func lookupFile(url: URL) -> File {
func updateFile(url: URL) -> File {
let file = File(url:url)

// This preseves the duration previously parsed and stored
Expand All @@ -270,6 +273,14 @@ func lookupFile(url: URL) -> File {
return file
}

func lookupFile(url: URL) -> File {
let file = File(url:url)
if let fileOld = fileCache[file.url] {
return fileOld
}
return file
}

func lookupFile(selection: String) -> File {
return lookupFile(url:URL(string:selection)!)
}
Expand Down Expand Up @@ -483,7 +494,7 @@ func listFilesFromArchive(_ urlArchive: URL) -> [File] {

// TODO: archives don't have full paths, so lookup can get confused
// if there are multiple archives with same paths.
let file = lookupFile(url:url)
let file = updateFile(url:url)
if file.archive != archive {
file.archive = archive
}
Expand Down Expand Up @@ -519,7 +530,7 @@ func listFilesFromURLs(_ urls: [URL]) -> [File]
files += listFilesFromArchive(fileURL)
}
else {
files.append(lookupFile(url:fileURL));
files.append(updateFile(url:fileURL));
}
}
}
Expand All @@ -532,7 +543,7 @@ func listFilesFromURLs(_ urls: [URL]) -> [File]
files += listFilesFromArchive(url)
}
else {
files.append(lookupFile(url:url))
files.append(updateFile(url:url))
}
}
}
Expand Down
21 changes: 8 additions & 13 deletions kram-profile/kram-profile/kram_profileApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func sortThreadsByName(_ catapultProfile: inout CatapultProfile) {
}

// these are per thread min/max for memory reports
func updateThreadInfo(_ catapultProfile: CatapultProfile, _ file: inout File) {
func updateThreadInfo(_ catapultProfile: CatapultProfile, _ file: File) {
// was using Set<>, but having trouble with lookup
var threadInfos: [Int: ThreadInfo] = [:]

Expand Down Expand Up @@ -1562,14 +1562,7 @@ func convertStatsToTotalTrack(_ stats: BuildStats) -> [CatapultEvent] {
return totalEvents
}

func loadFileJS(_ path: String) -> String? {

let fileURL = URL(string: path)!

// Note may need to modify directly
var file = lookupFile(url: fileURL)

log.debug(path)
func loadFileJS(_ file: File) -> String? {

do {
// use this for binary data, but need to fixup some json before it's sent
Expand Down Expand Up @@ -1621,7 +1614,7 @@ func loadFileJS(_ path: String) -> String? {

// For now, just log the per-thread info
if file.fileType == .Memory {
updateThreadInfo(catapultProfile, &file)
updateThreadInfo(catapultProfile, file)
}

// This mods the catapult profile to store parentIndex and durSub
Expand Down Expand Up @@ -1723,7 +1716,7 @@ func loadFileJS(_ path: String) -> String? {
fileContentBase64 = compressedData.base64EncodedString()
}

return postLoadFileJS(fileContentBase64: fileContentBase64, title:fileURL.lastPathComponent)
return postLoadFileJS(fileContentBase64: fileContentBase64, title:file.name)
}
catch {
log.error(error.localizedDescription)
Expand Down Expand Up @@ -1968,17 +1961,19 @@ struct kram_profileApp: App {
func openFileSelection(_ webView: WKWebView) {
if let sel = selection {

let file = lookupFile(selection: sel)

// This should only reload if selection previously loaded
// to a valid file, or if modstamp changed on current selection

// TODO: fix this
let objTimeScript: String? = nil // buildTimeRangeJson(filenameToTimeRange(sel))

var str = loadFileJS(sel)
var str = loadFileJS(file)
if str != nil {
runJavascript(webView, str!)

let file = lookupFile(selection: sel)
// This means Perfetto UI loaded the fileContent, not that fileContent was loaded
file.setLoadStamp()
}

Expand Down

0 comments on commit ac02908

Please sign in to comment.