Skip to content

Commit

Permalink
Debug: Rate limit bitbake progress bars
Browse files Browse the repository at this point in the history
This will make reading debug logs from the CI or users easier.
Each progress bar update every few milliseconds were duplicated,
resulting in a lot of noise in the logs.
  • Loading branch information
deribaucourt committed Jan 9, 2025
1 parent 14a6530 commit cb7dddb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/src/driver/BitbakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BitbakeDriver {
})
const disposables = [
child.onData((data) => {
logger.debug(data.toString())
logger.debug_ratelimit(data.toString())
}),
child.onExit(() => {
this.bitbakeProcess = undefined
Expand Down
32 changes: 32 additions & 0 deletions client/src/lib/src/utils/OutputLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ export class OutputLogger {
this.log(message, 'debug')
}

public debug_ratelimit (message: string): void {
if (!this.shouldLog(this.level)) {
// OPTIM Skip the regex check if the log level is not high enough
return
}

if (OutputLogger.rateLimitPatterns.test(message)) {
const now = Date.now()
if (now - this.rateLimitStart < OutputLogger.rateLimit) {
this.rateLimitCount++
return
}
this.rateLimitStart = now
if (this.rateLimitCount > 0) {
this.debug(`Rate limited ${this.rateLimitCount} messages`)
this.rateLimitCount = 0
}
}

this.debug(message)
}

/* Catches messages like:
* 0: busybox-1.37.0-r0 do_fetch - 6s (pid 280) 7% |######### | 28.7M/s
* Parsing recipes: 10% |################ | ETA: 0:00:19
* No currently running tasks (0 of 3) 0% | |
*/
private static readonly rateLimitPatterns = /% \|/
private static readonly rateLimit = 1000
private rateLimitStart = 0
private rateLimitCount = 0

public warn (message: string): void {
this.log(message, 'warning')
}
Expand Down

0 comments on commit cb7dddb

Please sign in to comment.