Skip to content

Commit

Permalink
Rate limit CPU warning logs from the Voice Focus worklet (#2252)
Browse files Browse the repository at this point in the history
* Rate limit CPU warning logs from the Voice Focus worklet

* Adjust CHANGELOG for Voice Focus CPU warning changes

* Reduce CPU warning interval to 5 seconds and adjust CHANGELOG

* Address comments

* Remove unnecessary CHANGELOG in 3.3.0

Co-authored-by: Richard Huang <[email protected]>
Co-authored-by: Venkatesh Devale <[email protected]>
  • Loading branch information
3 people authored May 26, 2022
1 parent 6fae98a commit a030477
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add reset function to uplink policy interface, and ignore indexes in nscale policy if the number of published videos did not change.

### Fixed
- Rate limited CPU warnings to at most once a minute in Voice Focus library, so that builder logs are not flooded.

## [3.3.0] - 2022-05-12

Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/decider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/fetch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidRevisionID = exports.isValidAssetGroup = exports.resolveURL = exports.addQueryParams = exports.withQueryString = exports.withRequestHeaders = exports.fetchWithBehavior = void 0;
Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/loader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadWorker = void 0;
Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/support.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand Down
1 change: 0 additions & 1 deletion libs/voicefocus/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,4 @@ export interface VoiceFocusFetchBehavior {
export interface VoiceFocusFetchConfig extends VoiceFocusFetchBehavior {
paths: VoiceFocusPaths;
}

export {};
3 changes: 3 additions & 0 deletions libs/voicefocus/types.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoiceFocusAudioWorkletNode = void 0;
Expand Down
13 changes: 8 additions & 5 deletions libs/voicefocus/voicefocus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand All @@ -23,12 +26,12 @@ const DEFAULT_AGC_DISABLED_SETTING = {
};
const DEFAULT_AGC_SETTING = DEFAULT_AGC_DISABLED_SETTING;
const DEFAULT_ASSET_GROUP = 'stable-v1';
const DEFAULT_CDN = 'https://static.sdkassets.chime.aws/';
const DEFAULT_CDN = 'https://static.sdkassets.chime.aws';
const DEFAULT_PATHS = {
processors: `${DEFAULT_CDN}processors/`,
workers: `${DEFAULT_CDN}workers/`,
wasm: `${DEFAULT_CDN}wasm/`,
models: `${DEFAULT_CDN}wasm/`,
processors: `${DEFAULT_CDN}/processors/`,
workers: `${DEFAULT_CDN}/workers/`,
wasm: `${DEFAULT_CDN}/wasm/`,
models: `${DEFAULT_CDN}/wasm/`,
};
const DEFAULT_CONTEXT_HINT = {
latencyHint: 0,
Expand Down
2 changes: 2 additions & 0 deletions libs/voicefocus/worklet-inline-node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ declare class VoiceFocusInlineNode extends VoiceFocusAudioWorkletNode {
private delegate?;
private worker;
private logger;
private cpuWarningLastTriggered;
private cpuWarningCount;
constructor(context: AudioContext, options: VoiceFocusNodeOptions);
onModuleBufferLoaded(buffer: ArrayBuffer, key: string): void;
onModuleLoaded(module: WebAssembly.Module, key: string): void;
Expand Down
15 changes: 14 additions & 1 deletion libs/voicefocus/worklet-inline-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand All @@ -11,9 +14,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const support_js_1 = require("./support.js");
const types_js_1 = require("./types.js");
const CPU_WARNING_MAX_INTERVAL_MS = 5 * 1000;
class VoiceFocusInlineNode extends types_js_1.VoiceFocusAudioWorkletNode {
constructor(context, options) {
super(context, options.processor, options);
this.cpuWarningCount = 0;
this.channelCountMode = 'explicit';
this.channelCount = 1;
const { modelURL, worker, fetchBehavior, logger, delegate, } = options;
Expand Down Expand Up @@ -59,7 +64,15 @@ class VoiceFocusInlineNode extends types_js_1.VoiceFocusAudioWorkletNode {
const data = event.data;
switch (data.message) {
case 'cpu':
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn('CPU warning:', data.message);
this.cpuWarningCount++;
const now = Date.now();
const before = this.cpuWarningLastTriggered || now;
const diff = Math.abs(now - before);
if (!this.cpuWarningLastTriggered || diff > CPU_WARNING_MAX_INTERVAL_MS) {
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`CPU warning (count: ${this.cpuWarningCount}):`, data.message);
this.cpuWarningCount = 0;
this.cpuWarningLastTriggered = now;
}
(_b = this.delegate) === null || _b === void 0 ? void 0 : _b.onCPUWarning();
break;
default:
Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/worklet-worker-postMessage-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand Down
3 changes: 3 additions & 0 deletions libs/voicefocus/worklet-worker-sab-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
Expand Down

0 comments on commit a030477

Please sign in to comment.