Procházet zdrojové kódy

feat(PerformanceObserverStats) remove it (#2809)

It hasn't been useful or used in years.
master
Saúl Ibarra Corretgé před 4 měsíci
rodič
revize
8ff323b5ee
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 0
- 5
JitsiConference.js Zobrazit soubor

484
         Statistics.analytics.addPermanentProperties({
484
         Statistics.analytics.addPermanentProperties({
485
             'callstats_name': this._statsCurrentId
485
             'callstats_name': this._statsCurrentId
486
         });
486
         });
487
-
488
-        // Start performance observer for monitoring long tasks
489
-        if (config.longTasksStatsInterval) {
490
-            this.statistics.attachLongTasksStats();
491
-        }
492
     }
487
     }
493
 
488
 
494
     this.eventManager.setupChatRoomListeners();
489
     this.eventManager.setupChatRoomListeners();

+ 0
- 97
modules/statistics/PerformanceObserverStats.js Zobrazit soubor

1
-
2
-import { getLogger } from '@jitsi/logger';
3
-
4
-import * as StatisticsEvents from '../../service/statistics/Events';
5
-import { RunningAverage } from '../util/MathUtil';
6
-
7
-const logger = getLogger('modules/statistics/PerformanceObserverStats');
8
-const MILLI_SECONDS = 1000;
9
-const SECONDS = 60;
10
-
11
-/**
12
- * This class creates an observer that monitors browser's performance measurement events
13
- * as they are recorded in the browser's performance timeline and computes an average and
14
- * a maximum value for the long task events. Tasks are classified as long tasks if they take
15
- * longer than 50ms to execute on the main thread.
16
- */
17
-export class PerformanceObserverStats {
18
-    /**
19
-     * Creates a new instance of Performance observer statistics.
20
-     *
21
-     * @param {*} emitter Event emitter for emitting stats periodically
22
-     * @param {*} statsInterval interval for calculating the stats
23
-     */
24
-    constructor(emitter, statsInterval) {
25
-        this.eventEmitter = emitter;
26
-        this.longTasks = 0;
27
-        this.maxDuration = 0;
28
-        this.performanceStatsInterval = statsInterval;
29
-        this.stats = new RunningAverage();
30
-    }
31
-
32
-    /**
33
-     * Obtains the average rate of long tasks observed per min and the
34
-     * duration of the longest task recorded by the observer.
35
-     * @returns {Object}
36
-     */
37
-    getLongTasksStats() {
38
-        return {
39
-            avgRatePerMinute: (this.stats.getAverage() * SECONDS).toFixed(2), // calc rate per min
40
-            maxDurationMs: this.maxDuration
41
-        };
42
-    }
43
-
44
-    /**
45
-     * Starts the performance observer by registering the callback function
46
-     * that calculates the performance statistics periodically.
47
-     * @returns {void}
48
-     */
49
-    startObserver() {
50
-        // Create a handler for when the long task event is fired.
51
-        this.longTaskEventHandler = list => {
52
-            const entries = list.getEntries();
53
-
54
-            for (const task of entries) {
55
-                this.longTasks++;
56
-                this.maxDuration = Math.max(this.maxDuration, task.duration).toFixed(3);
57
-            }
58
-        };
59
-
60
-        // Create an observer for monitoring long tasks.
61
-        logger.info('Creating a Performance Observer for monitoring Long Tasks');
62
-        this.observer = new PerformanceObserver(this.longTaskEventHandler);
63
-        this.observer.observe({ type: 'longtask',
64
-            buffered: true });
65
-        const startTime = Date.now();
66
-
67
-        // Calculate the average # of events/sec and emit a stats event.
68
-        this.longTasksIntervalId = setInterval(() => {
69
-            const now = Date.now();
70
-            const interval = this._lastTimeStamp
71
-                ? (now - this._lastTimeStamp) / MILLI_SECONDS
72
-                : (now - startTime) / MILLI_SECONDS;
73
-            const rate = this.longTasks / interval;
74
-
75
-            this.stats.addNext(rate);
76
-            this.eventEmitter.emit(
77
-                StatisticsEvents.LONG_TASKS_STATS, this.getLongTasksStats());
78
-
79
-            // Reset the counter and start counting events again.
80
-            this.longTasks = 0;
81
-            this._lastTimeStamp = Date.now();
82
-        }, this.performanceStatsInterval);
83
-    }
84
-
85
-    /**
86
-     * Stops the performance observer.
87
-     * @returns {void}
88
-     */
89
-    stopObserver() {
90
-        this.observer && this.observer.disconnect();
91
-        this.longTaskEventHandler = null;
92
-        if (this.longTasksIntervalId) {
93
-            clearInterval(this.longTasksIntervalId);
94
-            this.longTasksIntervalId = null;
95
-        }
96
-    }
97
-}

+ 0
- 67
modules/statistics/PerformanceObserverStats.spec.js Zobrazit soubor

1
-
2
-import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
3
-import browser from '../browser';
4
-import Listenable from '../util/Listenable';
5
-
6
-import Statistics from './statistics';
7
-
8
-/**
9
- * Mock object to be used in place of a real conference.
10
- *
11
- */
12
-class MockConference extends Listenable {
13
-    /**
14
-     * constructor
15
-     */
16
-    constructor() {
17
-        super();
18
-        this.options = {
19
-            config: {}
20
-        };
21
-    }
22
-}
23
-
24
-describe('PerformanceObserverStats', () => {
25
-    let mockConference, statistics;
26
-
27
-    beforeEach(() => {
28
-        // works only on chrome.
29
-        spyOn(browser, 'isChrome').and.returnValue(true);
30
-        mockConference = new MockConference();
31
-        Statistics.init({ longTasksStatsInterval: 1000 });
32
-        statistics = new Statistics(mockConference);
33
-        jasmine.clock().install();
34
-    });
35
-
36
-    it('Conference events start/stop observer', () => {
37
-        statistics.attachLongTasksStats(mockConference);
38
-        const startObserverSpy = spyOn(statistics.performanceObserverStats, 'startObserver');
39
-        const stopObserverSpy = spyOn(statistics.performanceObserverStats, 'stopObserver');
40
-
41
-        mockConference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
42
-        expect(startObserverSpy).toHaveBeenCalled();
43
-
44
-        mockConference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
45
-        expect(stopObserverSpy).toHaveBeenCalled();
46
-    });
47
-
48
-    it('Emits long tasks stats every sec', () => {
49
-        statistics.attachLongTasksStats(mockConference);
50
-        statistics.performanceObserverStats.eventEmitter = {
51
-            // eslint-disable-next-line no-empty-function
52
-            emit: () => {}
53
-        };
54
-        statistics.performanceObserverStats.startObserver();
55
-        const eventEmitSpy = spyOn(statistics.performanceObserverStats.eventEmitter, 'emit');
56
-
57
-        expect(statistics.performanceObserverStats.getLongTasksStats()).toBeTruthy();
58
-        expect(eventEmitSpy).not.toHaveBeenCalled();
59
-
60
-        jasmine.clock().tick(1000);
61
-        expect(eventEmitSpy).toHaveBeenCalled();
62
-    });
63
-
64
-    afterEach(() => {
65
-        jasmine.clock().uninstall();
66
-    });
67
-});

+ 0
- 31
modules/statistics/statistics.js Zobrazit soubor

1
-import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
2
 import { JitsiTrackEvents } from '../../JitsiTrackEvents';
1
 import { JitsiTrackEvents } from '../../JitsiTrackEvents';
3
 import { FEEDBACK } from '../../service/statistics/AnalyticsEvents';
2
 import { FEEDBACK } from '../../service/statistics/AnalyticsEvents';
4
 import * as StatisticsEvents from '../../service/statistics/Events';
3
 import * as StatisticsEvents from '../../service/statistics/Events';
9
 
8
 
10
 import analytics from './AnalyticsAdapter';
9
 import analytics from './AnalyticsAdapter';
11
 import LocalStats from './LocalStatsCollector';
10
 import LocalStats from './LocalStatsCollector';
12
-import { PerformanceObserverStats } from './PerformanceObserverStats';
13
 import RTPStats from './RTPStatsCollector';
11
 import RTPStats from './RTPStatsCollector';
14
 
12
 
15
 const logger = require('@jitsi/logger').getLogger('modules/statistics/statistics');
13
 const logger = require('@jitsi/logger').getLogger('modules/statistics/statistics');
34
         Statistics.audioLevelsInterval = options.audioLevelsInterval;
32
         Statistics.audioLevelsInterval = options.audioLevelsInterval;
35
     }
33
     }
36
 
34
 
37
-    if (typeof options.longTasksStatsInterval === 'number') {
38
-        Statistics.longTasksStatsInterval = options.longTasksStatsInterval;
39
-    }
40
-
41
     Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;
35
     Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;
42
 
36
 
43
     LocalStats.init();
37
     LocalStats.init();
229
     this.eventEmitter.on(StatisticsEvents.LONG_TASKS_STATS, listener);
223
     this.eventEmitter.on(StatisticsEvents.LONG_TASKS_STATS, listener);
230
 };
224
 };
231
 
225
 
232
-/**
233
- * Creates an instance of {@link PerformanceObserverStats} and starts the
234
- * observer that records the stats periodically.
235
- *
236
- * @returns {void}
237
- */
238
-Statistics.prototype.attachLongTasksStats = function() {
239
-    if (!browser.supportsPerformanceObserver()) {
240
-        logger.warn('Performance observer for long tasks not supported by browser!');
241
-
242
-        return;
243
-    }
244
-
245
-    this.performanceObserverStats = new PerformanceObserverStats(
246
-        this.eventEmitter,
247
-        Statistics.longTasksStatsInterval);
248
-
249
-    this.conference.on(
250
-        JitsiConferenceEvents.CONFERENCE_JOINED,
251
-        () => this.performanceObserverStats.startObserver());
252
-    this.conference.on(
253
-        JitsiConferenceEvents.CONFERENCE_LEFT,
254
-        () => this.performanceObserverStats.stopObserver());
255
-};
256
-
257
 /**
226
 /**
258
  * Obtains the current value of the LongTasks event statistics.
227
  * Obtains the current value of the LongTasks event statistics.
259
  *
228
  *

+ 0
- 6
types/hand-crafted/modules/statistics/PerformanceObserverStats.d.ts Zobrazit soubor

1
-export class PerformanceObserverStats {
2
-  constructor( emitter: unknown, statsInterval: unknown ); // TODO:
3
-  getLongTasksStats: () => unknown; // TODO:
4
-  startObserver: () => void;
5
-  stopObserver: () => void;
6
-}

Načítá se…
Zrušit
Uložit