From 53ccc3e0d7444e9ec509cfb91d424a329d16098b Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Fri, 15 Oct 2021 11:11:05 -0600 Subject: [PATCH] Add more cache debug logging --- src/cache-gradle-user-home.ts | 78 +++++++++++++++++++---------------- src/cache-utils.ts | 6 +++ 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index a07e562..3907daf 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -26,9 +26,9 @@ export class GradleUserHomeCache extends AbstractCache { } async afterRestore(): Promise { - await this.reportCacheEntrySize('as restored from cache') + await this.reportGradleUserHomeSize('as restored from cache') await this.restoreCommonArtifacts() - await this.reportCacheEntrySize('after restoring common artifacts') + await this.reportGradleUserHomeSize('after restoring common artifacts') } private async restoreCommonArtifacts(): Promise { @@ -59,7 +59,7 @@ export class GradleUserHomeCache extends AbstractCache { ) } else { this.debug( - `Failed to restore ${bundle} with key ${cacheKey} to ${artifactPath}` + `Did not restore ${bundle} with key ${cacheKey} to ${artifactPath}` ) } } else { @@ -77,41 +77,10 @@ export class GradleUserHomeCache extends AbstractCache { ) } - private async reportCacheEntrySize(label: string): Promise { - 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 { + await this.reportGradleUserHomeSize('before saving common artifacts') await this.saveCommonArtifacts() + await this.reportGradleUserHomeSize('after saving common artifacts') } private async saveCommonArtifacts(): Promise { @@ -175,6 +144,10 @@ export class GradleUserHomeCache extends AbstractCache { ) const key = hashFileNames(relativeFiles) + this.debug( + `Generating cache key for ${bundle} from files: ${relativeFiles}` + ) + return `${cacheKeyPrefix}${bundle}-${key}` } @@ -205,4 +178,37 @@ export class GradleUserHomeCache extends AbstractCache { ]) ) } + + private async reportGradleUserHomeSize(label: string): Promise { + 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('-----------------------') + } } diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 162a92c..ad49850 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -122,6 +122,12 @@ export abstract class AbstractCache { core.saveState(this.cacheKeyStateKey, cacheKey.key) + this.debug( + `Requesting ${this.cacheDescription} with + key:${cacheKey.key} + restoreKeys:[${cacheKey.restoreKeys}]` + ) + const cacheResult = await this.restoreCache( this.getCachePath(), cacheKey.key,