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 13, 2024
1 parent 2e6956c commit caf338e
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions build/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,56 +111,58 @@ func statsPath(path string) string {
return path
}

func StatsString() string {
buf := &strings.Builder{}

func CountersString() string {
if len(Counters) == 0 {
fmt.Fprint(buf, "gn-counters: no counters")
} else {
keys := make([]string, 0, len(Counters))
width := 0
for k := range Counters {
keys = append(keys, k)
if len(k) > width {
width = len(k)
}
return "gn-counters: no counters"
}

buf := &strings.Builder{}
keys := make([]string, 0, len(Counters))
width := 0
for k := range Counters {
keys = append(keys, k)
if len(k) > width {
width = len(k)
}
sort.Strings(keys)
}
sort.Strings(keys)

for i, k := range keys {
if i > 0 {
fmt.Fprint(buf, "\n")
}
fmt.Fprintf(buf, "gn-counters: %-*s\t%d", width, k, Counters[k])
for i, k := range keys {
if i > 0 {
fmt.Fprint(buf, "\n")
}
fmt.Fprintf(buf, "gn-counters: %-*s\t%d", width, k, Counters[k])
}
return buf.String()
}

func FilePathString() string {
if len(FilePaths) == 0 {
fmt.Fprint(buf, "\ngn-filepaths: no file paths")
} else {
imports := make([]string, 0, len(FilePaths))
for im := range FilePaths {
imports = append(imports, im)
return "gn-filepaths: no file paths"
}

buf := &strings.Builder{}
imports := make([]string, 0, len(FilePaths))
for im := range FilePaths {
imports = append(imports, im)
}
sort.Strings(imports)
fmt.Fprint(buf, "gn-filepaths: ")
for _, im := range imports {
fmt.Fprintf(buf, "{%s::", im)
fp := FilePaths[im]
if fp.StoreCount > 0 {
fmt.Fprintf(buf, "%s(%d)", statsPath(fp.StorePath), fp.StoreCount)
}
sort.Strings(imports)
fmt.Fprint(buf, "\ngn-filepaths: ")
for _, im := range imports {
fmt.Fprintf(buf, "{%s: ", im)
fp := FilePaths[im]
if fp.StoreCount > 0 {
fmt.Fprintf(buf, "%s (%d)", statsPath(fp.StorePath), fp.StoreCount)
}
if fp.LoadCount > 0 {
if fp.StorePath == fp.LoadPath {
fmt.Fprintf(buf, "-(%d)", fp.LoadCount)
} else {
fmt.Fprintf(buf, "- %s (%d)", statsPath(fp.LoadPath), fp.LoadCount)
}
if fp.LoadCount > 0 {
if fp.StorePath == fp.LoadPath {
fmt.Fprintf(buf, "-:(%d)", fp.LoadCount)
} else {
fmt.Fprintf(buf, "-%s(%d)", statsPath(fp.LoadPath), fp.LoadCount)
}
fmt.Fprintf(buf, "}")
}
fmt.Fprintf(buf, "}, ")
}

return buf.String()
}

Expand Down Expand Up @@ -280,5 +282,9 @@ func (bc *BuildCache) CommonKey() string {

// 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)
bc2 := *bc
if bc.TestedPackage != importPath {
bc2.TestedPackage = ``
}
return path.Join("archive", bc2.CommonKey(), importPath)
}

0 comments on commit caf338e

Please sign in to comment.