Skip to content

Commit

Permalink
Adding in cache testing
Browse files Browse the repository at this point in the history
  • Loading branch information
grantnelson-wf committed Dec 12, 2024
1 parent 98ea5ad commit 9c7fbd0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@ func NewSession(options *Options) (*Session, error) {
return s, nil
}

func (s *Session) CacheCommonKey() string {
return s.buildCache.CommonKey()
}

// XContext returns the session's build context.
func (s *Session) XContext() XContext { return s.xctx }

Expand Down
16 changes: 11 additions & 5 deletions build/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ func StatsString() string {
sort.Strings(imports)
fmt.Fprint(buf, "\ngn-filepaths: ")
for _, im := range imports {
fmt.Fprintf(buf, "{%s:", im)
fmt.Fprintf(buf, "{%s: ", im)
fp := FilePaths[im]
if fp.StoreCount > 0 {
fmt.Fprintf(buf, "%s (%d)", fp.StorePath, fp.StoreCount)
}
if fp.LoadCount > 0 {
if fp.StorePath == fp.LoadPath {
fmt.Fprintf(buf, "- \" (%d)", fp.LoadCount)
fmt.Fprintf(buf, " - \" (%d)", fp.LoadCount)
} else {
fmt.Fprintf(buf, "- %s (%d)", fp.LoadPath, fp.LoadCount)
fmt.Fprintf(buf, " - %s (%d)", fp.LoadPath, fp.LoadCount)
}
}
fmt.Fprintf(buf, "}")
Expand All @@ -160,6 +160,9 @@ func recordStorePath(importPath, storePath string) {
fp = &FilePathStats{}
FilePaths[importPath] = fp
}
if strings.HasPrefix(storePath, cacheRoot) {
storePath = storePath[len(cacheRoot):]
}
if fp.StorePath != "" && fp.StorePath != storePath {
fmt.Printf("store path mismatch: %s, old %s, new: %s\n", importPath, fp.StorePath, storePath)
}
Expand All @@ -173,6 +176,9 @@ func recordLoadPath(importPath, loadPath string) {
fp = &FilePathStats{}
FilePaths[importPath] = fp
}
if strings.HasPrefix(loadPath, cacheRoot) {
loadPath = loadPath[len(cacheRoot):]
}
if fp.LoadPath != "" && fp.LoadPath != loadPath {
fmt.Printf("load path mismatch: %s, old %s, new: %s\n", importPath, fp.LoadPath, loadPath)
}
Expand Down Expand Up @@ -258,11 +264,11 @@ func (bc *BuildCache) LoadArchive(importPath string) *compiler.Archive {

// commonKey returns a part of the cache key common for all artifacts generated
// under a given BuildCache configuration.
func (bc *BuildCache) commonKey() string {
func (bc *BuildCache) CommonKey() string {
return fmt.Sprintf("%#v + %v", *bc, compiler.Version)
}

// archiveKey returns a full cache key for a package's compiled archive.
func (bc *BuildCache) archiveKey(importPath string) string {
return path.Join("archive", bc.commonKey(), importPath)
return path.Join("archive", bc.CommonKey(), importPath)
}
1 change: 1 addition & 0 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ func main() {
fmt.Println("---[build stats]---")
fmt.Println(pkg.ImportPath)
fmt.Println(tK.String())
fmt.Printf("gn-cacheCommonKey: %s\n", s.CacheCommonKey())
fmt.Println(cache.StatsString())
fmt.Println("-------------------")

Expand Down

0 comments on commit 9c7fbd0

Please sign in to comment.