Commit f7800a90 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'dmishunov-snippet-user-timing' into 'master'

User timing performance marks and measurements for snippets

See merge request gitlab-org/gitlab!30234
parents 576fea81 5e016f5b
<script> <script>
import { initEditorLite } from '~/blob/utils'; import { initEditorLite } from '~/blob/utils';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import {
SNIPPET_MARK_BLOBS_CONTENT,
SNIPPET_MARK_EDIT_APP_START,
SNIPPET_MEASURE_BLOBS_CONTENT,
SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP,
} from '~/performance_constants';
export default { export default {
props: { props: {
...@@ -31,6 +37,13 @@ export default { ...@@ -31,6 +37,13 @@ export default {
blobPath: this.fileName, blobPath: this.fileName,
blobContent: this.value, blobContent: this.value,
}); });
window.requestAnimationFrame(() => {
if (!performance.getEntriesByName(SNIPPET_MARK_BLOBS_CONTENT).length) {
performance.mark(SNIPPET_MARK_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP, SNIPPET_MARK_EDIT_APP_START);
}
});
}, },
methods: { methods: {
triggerFileChange: debounce(function debouncedFileChange() { triggerFileChange: debounce(function debouncedFileChange() {
......
//
// SNIPPET namespace
//
// marks
export const SNIPPET_MARK_VIEW_APP_START = 'snippet-view-app-start';
export const SNIPPET_MARK_EDIT_APP_START = 'snippet-edit-app-start';
export const SNIPPET_MARK_BLOBS_CONTENT = 'snippet-blobs-content-finished';
// Measures
export const SNIPPET_MEASURE_BLOBS_CONTENT = 'snippet-blobs-content';
export const SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP = 'snippet-blobs-content-within-app';
...@@ -21,6 +21,7 @@ import { ...@@ -21,6 +21,7 @@ import {
import SnippetBlobEdit from './snippet_blob_edit.vue'; import SnippetBlobEdit from './snippet_blob_edit.vue';
import SnippetVisibilityEdit from './snippet_visibility_edit.vue'; import SnippetVisibilityEdit from './snippet_visibility_edit.vue';
import SnippetDescriptionEdit from './snippet_description_edit.vue'; import SnippetDescriptionEdit from './snippet_description_edit.vue';
import { SNIPPET_MARK_EDIT_APP_START } from '~/performance_constants';
export default { export default {
components: { components: {
...@@ -106,6 +107,9 @@ export default { ...@@ -106,6 +107,9 @@ export default {
return `${this.isProjectSnippet ? 'project' : 'personal'}_snippet_description`; return `${this.isProjectSnippet ? 'project' : 'personal'}_snippet_description`;
}, },
}, },
beforeCreate() {
performance.mark(SNIPPET_MARK_EDIT_APP_START);
},
created() { created() {
window.addEventListener('beforeunload', this.onBeforeUnload); window.addEventListener('beforeunload', this.onBeforeUnload);
}, },
......
...@@ -9,6 +9,8 @@ import { GlLoadingIcon } from '@gitlab/ui'; ...@@ -9,6 +9,8 @@ import { GlLoadingIcon } from '@gitlab/ui';
import { getSnippetMixin } from '../mixins/snippets'; import { getSnippetMixin } from '../mixins/snippets';
import { SNIPPET_VISIBILITY_PUBLIC } from '~/snippets/constants'; import { SNIPPET_VISIBILITY_PUBLIC } from '~/snippets/constants';
import { SNIPPET_MARK_VIEW_APP_START } from '~/performance_constants';
export default { export default {
components: { components: {
BlobEmbeddable, BlobEmbeddable,
...@@ -27,6 +29,9 @@ export default { ...@@ -27,6 +29,9 @@ export default {
return Boolean(this.snippet.sshUrlToRepo || this.snippet.httpUrlToRepo); return Boolean(this.snippet.sshUrlToRepo || this.snippet.httpUrlToRepo);
}, },
}, },
beforeCreate() {
performance.mark(SNIPPET_MARK_VIEW_APP_START);
},
}; };
</script> </script>
<template> <template>
......
import {
SNIPPET_MARK_VIEW_APP_START,
SNIPPET_MARK_BLOBS_CONTENT,
SNIPPET_MEASURE_BLOBS_CONTENT,
SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP,
} from '~/performance_constants';
export default { export default {
props: { props: {
content: { content: {
...@@ -9,4 +16,13 @@ export default { ...@@ -9,4 +16,13 @@ export default {
required: true, required: true,
}, },
}, },
mounted() {
window.requestAnimationFrame(() => {
if (!performance.getEntriesByName(SNIPPET_MARK_BLOBS_CONTENT).length) {
performance.mark(SNIPPET_MARK_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT);
performance.measure(SNIPPET_MEASURE_BLOBS_CONTENT_WITHIN_APP, SNIPPET_MARK_VIEW_APP_START);
}
});
},
}; };
...@@ -52,6 +52,12 @@ class CustomEnvironment extends JSDOMEnvironment { ...@@ -52,6 +52,12 @@ class CustomEnvironment extends JSDOMEnvironment {
// Expose the jsdom (created in super class) to the global so that we can call reconfigure({ url: '' }) to properly set `window.location` // Expose the jsdom (created in super class) to the global so that we can call reconfigure({ url: '' }) to properly set `window.location`
this.global.dom = this.dom; this.global.dom = this.dom;
Object.assign(this.global.performance, {
mark: () => null,
measure: () => null,
getEntriesByName: () => [],
});
} }
async teardown() { async teardown() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment