Add more cache debug logging

This commit is contained in:
Daz DeBoer 2021-10-15 11:11:05 -06:00
parent 8ab7c9d8dd
commit 53ccc3e0d7
No known key found for this signature in database
GPG Key ID: DD6B9F0B06683D5D
2 changed files with 48 additions and 36 deletions

View File

@ -26,9 +26,9 @@ export class GradleUserHomeCache extends AbstractCache {
} }
async afterRestore(): Promise<void> { async afterRestore(): Promise<void> {
await this.reportCacheEntrySize('as restored from cache') await this.reportGradleUserHomeSize('as restored from cache')
await this.restoreCommonArtifacts() await this.restoreCommonArtifacts()
await this.reportCacheEntrySize('after restoring common artifacts') await this.reportGradleUserHomeSize('after restoring common artifacts')
} }
private async restoreCommonArtifacts(): Promise<void> { private async restoreCommonArtifacts(): Promise<void> {
@ -59,7 +59,7 @@ export class GradleUserHomeCache extends AbstractCache {
) )
} else { } else {
this.debug( this.debug(
`Failed to restore ${bundle} with key ${cacheKey} to ${artifactPath}` `Did not restore ${bundle} with key ${cacheKey} to ${artifactPath}`
) )
} }
} else { } else {
@ -77,41 +77,10 @@ export class GradleUserHomeCache extends AbstractCache {
) )
} }
private async reportCacheEntrySize(label: string): Promise<void> {
if (!this.cacheDebuggingEnabled) {
return
}
if (!fs.existsSync(this.gradleUserHome)) {
return
}
const result = await exec.getExecOutput(
'du',
['-h', '-c', '-t', '5M'],
{
cwd: this.gradleUserHome,
silent: true,
ignoreReturnCode: true
}
)
core.info(`Gradle User Home cache entry (directories >5M): ${label}`)
core.info(
result.stdout
.trimEnd()
.replace(/\t/g, ' ')
.split('\n')
.map(it => {
return ` ${it}`
})
.join('\n')
)
core.info('-----------------------')
}
async beforeSave(): Promise<void> { async beforeSave(): Promise<void> {
await this.reportGradleUserHomeSize('before saving common artifacts')
await this.saveCommonArtifacts() await this.saveCommonArtifacts()
await this.reportGradleUserHomeSize('after saving common artifacts')
} }
private async saveCommonArtifacts(): Promise<void> { private async saveCommonArtifacts(): Promise<void> {
@ -175,6 +144,10 @@ export class GradleUserHomeCache extends AbstractCache {
) )
const key = hashFileNames(relativeFiles) const key = hashFileNames(relativeFiles)
this.debug(
`Generating cache key for ${bundle} from files: ${relativeFiles}`
)
return `${cacheKeyPrefix}${bundle}-${key}` return `${cacheKeyPrefix}${bundle}-${key}`
} }
@ -205,4 +178,37 @@ export class GradleUserHomeCache extends AbstractCache {
]) ])
) )
} }
private async reportGradleUserHomeSize(label: string): Promise<void> {
if (!this.cacheDebuggingEnabled) {
return
}
if (!fs.existsSync(this.gradleUserHome)) {
return
}
const result = await exec.getExecOutput(
'du',
['-h', '-c', '-t', '5M'],
{
cwd: this.gradleUserHome,
silent: true,
ignoreReturnCode: true
}
)
core.info(`Gradle User Home cache entry (directories >5M): ${label}`)
core.info(
result.stdout
.trimEnd()
.replace(/\t/g, ' ')
.split('\n')
.map(it => {
return ` ${it}`
})
.join('\n')
)
core.info('-----------------------')
}
} }

View File

@ -122,6 +122,12 @@ export abstract class AbstractCache {
core.saveState(this.cacheKeyStateKey, cacheKey.key) core.saveState(this.cacheKeyStateKey, cacheKey.key)
this.debug(
`Requesting ${this.cacheDescription} with
key:${cacheKey.key}
restoreKeys:[${cacheKey.restoreKeys}]`
)
const cacheResult = await this.restoreCache( const cacheResult = await this.restoreCache(
this.getCachePath(), this.getCachePath(),
cacheKey.key, cacheKey.key,