mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #10063 from overleaf/td-extra-editing-session-metrics
Add extra editing session metrics GitOrigin-RevId: d382719364e9fe029cd664e77608faa50204e0e0
This commit is contained in:
parent
b299ccf139
commit
3dbcc03db2
3 changed files with 54 additions and 13 deletions
|
@ -269,15 +269,26 @@ If the project has been renamed please look in your project list for a new proje
|
||||||
|
|
||||||
// Ignore if no typing has happened
|
// Ignore if no typing has happened
|
||||||
if (cm6PerfData.numberOfEntries > 0) {
|
if (cm6PerfData.numberOfEntries > 0) {
|
||||||
segmentation.cm6PerfMax = cm6PerfData.max
|
const perfProps = [
|
||||||
segmentation.cm6PerfMean = cm6PerfData.mean
|
'Max',
|
||||||
segmentation.cm6PerfMedian = cm6PerfData.median
|
'Mean',
|
||||||
segmentation.cm6PerfNinetyFifthPercentile =
|
'Median',
|
||||||
cm6PerfData.ninetyFifthPercentile
|
'NinetyFifthPercentile',
|
||||||
segmentation.cm6PerfDocLength = cm6PerfData.docLength
|
'DocLength',
|
||||||
segmentation.cm6PerfNumberOfEntries = cm6PerfData.numberOfEntries
|
'NumberOfEntries',
|
||||||
segmentation.cm6PerfMaxUserEventsBetweenDomUpdates =
|
'MaxUserEventsBetweenDomUpdates',
|
||||||
cm6PerfData.maxUserEventsBetweenDomUpdates
|
'Grammarly',
|
||||||
|
'SessionLength',
|
||||||
|
'Memory',
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const prop of perfProps) {
|
||||||
|
const perfValue =
|
||||||
|
cm6PerfData[prop.charAt(0).toLowerCase() + prop.slice(1)]
|
||||||
|
if (perfValue !== null) {
|
||||||
|
segmentation['cm6Perf' + prop] = perfValue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import { Transaction } from '@codemirror/state'
|
import { Transaction } from '@codemirror/state'
|
||||||
import { EditorView } from '@codemirror/view'
|
import { EditorView } from '@codemirror/view'
|
||||||
|
import { round } from 'lodash'
|
||||||
|
import grammarlyExtensionPresent from '../shared/utils/grammarly'
|
||||||
|
|
||||||
const TIMER_START_NAME = 'CM6-BeforeUpdate'
|
const TIMER_START_NAME = 'CM6-BeforeUpdate'
|
||||||
const TIMER_END_NAME = 'CM6-AfterUpdate'
|
const TIMER_END_NAME = 'CM6-AfterUpdate'
|
||||||
const TIMER_MEASURE_NAME = 'CM6-Update'
|
const TIMER_MEASURE_NAME = 'CM6-Update'
|
||||||
|
|
||||||
let latestDocLength = 0
|
let latestDocLength = 0
|
||||||
|
const sessionStart = Date.now()
|
||||||
|
|
||||||
let performanceMeasureOptionsSupport = false
|
let performanceMeasureOptionsSupport = false
|
||||||
|
|
||||||
|
@ -17,6 +20,20 @@ try {
|
||||||
performanceMeasureOptionsSupport = true
|
performanceMeasureOptionsSupport = true
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
let performanceMemorySupport = false
|
||||||
|
|
||||||
|
function measureMemoryUsage() {
|
||||||
|
// @ts-ignore
|
||||||
|
return performance.memory.usedJSHeapSize
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ('memory' in window.performance) {
|
||||||
|
measureMemoryUsage()
|
||||||
|
performanceMemorySupport = true
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
function isInputOrDelete(userEventType: string | undefined) {
|
function isInputOrDelete(userEventType: string | undefined) {
|
||||||
return (
|
return (
|
||||||
!!userEventType && ['input', 'delete'].includes(userEventType.split('.')[0])
|
!!userEventType && ['input', 'delete'].includes(userEventType.split('.')[0])
|
||||||
|
@ -111,16 +128,23 @@ export function reportCM6Perf() {
|
||||||
.map(({ duration }) => duration)
|
.map(({ duration }) => duration)
|
||||||
.sort((a, b) => a - b)
|
.sort((a, b) => a - b)
|
||||||
|
|
||||||
const max = calculateMax(inputDurations)
|
const max = round(calculateMax(inputDurations), 2)
|
||||||
const mean = calculateMean(inputDurations)
|
const mean = round(calculateMean(inputDurations), 2)
|
||||||
const median = calculateMedian(inputDurations)
|
const median = round(calculateMedian(inputDurations), 2)
|
||||||
const ninetyFifthPercentile = calculate95thPercentile(inputDurations)
|
const ninetyFifthPercentile = round(
|
||||||
|
calculate95thPercentile(inputDurations),
|
||||||
|
2
|
||||||
|
)
|
||||||
const maxUserEventsBetweenDomUpdates = calculateMax(
|
const maxUserEventsBetweenDomUpdates = calculateMax(
|
||||||
inputEvents.map(e => e.detail.userEventsSinceDomUpdateCount)
|
inputEvents.map(e => e.detail.userEventsSinceDomUpdateCount)
|
||||||
)
|
)
|
||||||
|
const grammarly = grammarlyExtensionPresent()
|
||||||
|
const sessionLength = Math.floor((Date.now() - sessionStart) / 1000) // In seconds
|
||||||
|
|
||||||
performance.clearMeasures(TIMER_MEASURE_NAME)
|
performance.clearMeasures(TIMER_MEASURE_NAME)
|
||||||
|
|
||||||
|
const memory = performanceMemorySupport ? measureMemoryUsage() : null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
max,
|
max,
|
||||||
mean,
|
mean,
|
||||||
|
@ -129,6 +153,9 @@ export function reportCM6Perf() {
|
||||||
maxUserEventsBetweenDomUpdates,
|
maxUserEventsBetweenDomUpdates,
|
||||||
docLength: latestDocLength,
|
docLength: latestDocLength,
|
||||||
numberOfEntries: inputDurations.length,
|
numberOfEntries: inputDurations.length,
|
||||||
|
grammarly,
|
||||||
|
sessionLength,
|
||||||
|
memory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
services/web/frontend/js/shared/utils/grammarly.js
Normal file
3
services/web/frontend/js/shared/utils/grammarly.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default function grammarlyExtensionPresent() {
|
||||||
|
return !!document.querySelector('grammarly-desktop-integration')
|
||||||
|
}
|
Loading…
Reference in a new issue