Bläddra i källkod

Adds logThreshold to debug/log decorators

Logs storage calls if they take too long
main
Eric Amodio 2 år sedan
förälder
incheckning
b2fa25b978
6 ändrade filer med 33 tillägg och 11 borttagningar
  1. +1
    -1
      src/env/node/git/localGitProvider.ts
  2. +1
    -1
      src/git/gitProviderService.ts
  3. +1
    -0
      src/git/models/repository.ts
  4. +1
    -1
      src/plus/github/githubGitProvider.ts
  5. +10
    -0
      src/storage.ts
  6. +19
    -8
      src/system/decorators/log.ts

+ 1
- 1
src/env/node/git/localGitProvider.ts Visa fil

@ -905,7 +905,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
}
@log()
@log({ singleLine: true })
resetCaches(...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[]) {
if (affects.length === 0 || affects.includes('branches')) {
this._branchesCache.clear();

+ 1
- 1
src/git/gitProviderService.ts Visa fil

@ -960,7 +960,7 @@ export class GitProviderService implements Disposable {
return provider.checkout(path, ref, options);
}
@log()
@log({ singleLine: true })
resetCaches(
...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[]
): void {

+ 1
- 0
src/git/models/repository.ts Visa fil

@ -819,6 +819,7 @@ export class Repository implements Disposable {
this.runTerminalCommand('reset', ...args);
}
@log({ singleLine: true })
resetCaches(...affects: ('branches' | 'remotes')[]) {
if (affects.length === 0 || affects.includes('branches')) {
this._branch = undefined;

+ 1
- 1
src/plus/github/githubGitProvider.ts Visa fil

@ -365,7 +365,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
_options?: { createBranch?: string } | { path?: string },
): Promise<void> {}
@log()
@log({ singleLine: true })
resetCaches(
...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[]
): void {

+ 10
- 0
src/storage.ts Visa fil

@ -4,6 +4,7 @@ import { EventEmitter } from 'vscode';
import type { ViewShowBranchComparison } from './config';
import type { StoredSearchQuery } from './git/search';
import type { Subscription } from './subscription';
import { debug } from './system/decorators/log';
import type { TrackedUsage, TrackedUsageKeys } from './usageTracker';
import type { CompletedActions } from './webviews/home/protocol';
@ -48,6 +49,7 @@ export class Storage implements Disposable {
key: T,
defaultValue: NonNullable<GlobalStoragePathValue<T>>,
): NonNullable<GlobalStoragePathValue<T>>;
@debug({ logThreshold: 50 })
get<T extends GlobalStoragePath>(
key: T,
defaultValue?: GlobalStoragePathValue<T>,
@ -55,24 +57,29 @@ export class Storage implements Disposable {
return this.context.globalState.get(`gitlens:${key}`, defaultValue);
}
@debug({ logThreshold: 250 })
async delete<T extends GlobalStoragePath>(key: T): Promise<void> {
await this.context.globalState.update(`gitlens:${key}`, undefined);
this._onDidChange.fire({ key: key, workspace: false });
}
@debug({ args: { 1: false }, logThreshold: 250 })
async store<T extends GlobalStoragePath>(key: T, value: GlobalStoragePathValue<T>): Promise<void> {
await this.context.globalState.update(`gitlens:${key}`, value);
this._onDidChange.fire({ key: key, workspace: false });
}
@debug({ args: false, logThreshold: 250 })
async getSecret(key: SecretKeys): Promise<string | undefined> {
return this.context.secrets.get(key);
}
@debug({ args: false, logThreshold: 250 })
async deleteSecret(key: SecretKeys): Promise<void> {
return this.context.secrets.delete(key);
}
@debug({ args: false, logThreshold: 250 })
async storeSecret(key: SecretKeys, value: string): Promise<void> {
return this.context.secrets.store(key, value);
}
@ -82,6 +89,7 @@ export class Storage implements Disposable {
key: T,
defaultValue: NonNullable<WorkspaceStoragePathValue<T>>,
): NonNullable<WorkspaceStoragePathValue<T>>;
@debug({ logThreshold: 25 })
getWorkspace<T extends WorkspaceStoragePath>(
key: T,
defaultValue?: WorkspaceStoragePathValue<T>,
@ -89,11 +97,13 @@ export class Storage implements Disposable {
return this.context.workspaceState.get(`gitlens:${key}`, defaultValue);
}
@debug({ logThreshold: 250 })
async deleteWorkspace<T extends WorkspaceStoragePath>(key: T): Promise<void> {
await this.context.workspaceState.update(`gitlens:${key}`, undefined);
this._onDidChange.fire({ key: key, workspace: true });
}
@debug({ args: { 1: false }, logThreshold: 250 })
async storeWorkspace<T extends WorkspaceStoragePath>(key: T, value: WorkspaceStoragePathValue<T>): Promise<void> {
await this.context.workspaceState.update(`gitlens:${key}`, value);
this._onDidChange.fire({ key: key, workspace: true });

+ 19
- 8
src/system/decorators/log.ts Visa fil

@ -67,6 +67,7 @@ interface LogOptions any> {
exit?(result: PromiseType<ReturnType<T>>): string;
prefix?(context: LogContext, ...args: Parameters<T>): string;
sanitize?(key: string, value: any): any;
logThreshold?: number;
scoped?: boolean;
singleLine?: boolean;
timed?: boolean;
@ -93,6 +94,7 @@ export function log any>(options?: LogOptions, deb
let exitFn: LogOptions<T>['exit'] | undefined;
let prefixFn: LogOptions<T>['prefix'] | undefined;
let sanitizeFn: LogOptions<T>['sanitize'] | undefined;
let logThreshold = 0;
let scoped = false;
let singleLine = false;
let timed = true;
@ -104,12 +106,18 @@ export function log any>(options?: LogOptions, deb
exit: exitFn,
prefix: prefixFn,
sanitize: sanitizeFn,
logThreshold = 0,
scoped = true,
singleLine = false,
timed = true,
} = options);
}
if (logThreshold > 0) {
singleLine = true;
timed = true;
}
if (timed) {
scoped = true;
}
@ -264,10 +272,11 @@ export function log any>(options?: LogOptions, deb
}
const logResult = (r: any) => {
let duration: number | undefined;
let exitLogFn;
let timing;
if (start != null) {
const duration = getDurationMilliseconds(start);
duration = getDurationMilliseconds(start);
if (duration > Logger.slowCallWarningThreshold) {
exitLogFn = warnFn;
timing = ` \u2022 ${duration} ms (slow)`;
@ -292,13 +301,15 @@ export function log any>(options?: LogOptions, deb
}
if (singleLine) {
exitLogFn(
`${prefix}${enter}${
loggableParams && (debug || Logger.enabled(LogLevel.Debug) || Logger.isDebugging)
? `(${loggableParams})`
: emptyStr
} ${exit}${scope?.exitDetails ? scope.exitDetails : emptyStr}${timing}`,
);
if (logThreshold === 0 || duration! > logThreshold) {
exitLogFn(
`${prefix}${enter}${
loggableParams && (debug || Logger.enabled(LogLevel.Debug) || Logger.isDebugging)
? `(${loggableParams})`
: emptyStr
} ${exit}${scope?.exitDetails ? scope.exitDetails : emptyStr}${timing}`,
);
}
} else {
exitLogFn(
`${prefix}${

Laddar…
Avbryt
Spara