diff options
Diffstat (limited to 'app/assets/javascripts/diffs/utils')
-rw-r--r-- | app/assets/javascripts/diffs/utils/performance.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/utils/performance.js b/app/assets/javascripts/diffs/utils/performance.js new file mode 100644 index 00000000000..dcde6f4ecc4 --- /dev/null +++ b/app/assets/javascripts/diffs/utils/performance.js @@ -0,0 +1,80 @@ +import { performanceMarkAndMeasure } from '~/performance/utils'; +import { + MR_DIFFS_MARK_FILE_TREE_START, + MR_DIFFS_MARK_FILE_TREE_END, + MR_DIFFS_MARK_DIFF_FILES_START, + MR_DIFFS_MARK_FIRST_DIFF_FILE_SHOWN, + MR_DIFFS_MARK_DIFF_FILES_END, + MR_DIFFS_MEASURE_FILE_TREE_DONE, + MR_DIFFS_MEASURE_DIFF_FILES_DONE, +} from '../../performance/constants'; + +import eventHub from '../event_hub'; +import { + EVT_PERF_MARK_FILE_TREE_START, + EVT_PERF_MARK_FILE_TREE_END, + EVT_PERF_MARK_DIFF_FILES_START, + EVT_PERF_MARK_FIRST_DIFF_FILE_SHOWN, + EVT_PERF_MARK_DIFF_FILES_END, +} from '../constants'; + +function treeStart() { + performanceMarkAndMeasure({ + mark: MR_DIFFS_MARK_FILE_TREE_START, + }); +} + +function treeEnd() { + performanceMarkAndMeasure({ + mark: MR_DIFFS_MARK_FILE_TREE_END, + measures: [ + { + name: MR_DIFFS_MEASURE_FILE_TREE_DONE, + start: MR_DIFFS_MARK_FILE_TREE_START, + end: MR_DIFFS_MARK_FILE_TREE_END, + }, + ], + }); +} + +function filesStart() { + performanceMarkAndMeasure({ + mark: MR_DIFFS_MARK_DIFF_FILES_START, + }); +} + +function filesEnd() { + performanceMarkAndMeasure({ + mark: MR_DIFFS_MARK_DIFF_FILES_END, + measures: [ + { + name: MR_DIFFS_MEASURE_DIFF_FILES_DONE, + start: MR_DIFFS_MARK_DIFF_FILES_START, + end: MR_DIFFS_MARK_DIFF_FILES_END, + }, + ], + }); +} + +function firstFile() { + performanceMarkAndMeasure({ + mark: MR_DIFFS_MARK_FIRST_DIFF_FILE_SHOWN, + }); +} + +export const diffsApp = { + instrument() { + eventHub.$on(EVT_PERF_MARK_FILE_TREE_START, treeStart); + eventHub.$on(EVT_PERF_MARK_FILE_TREE_END, treeEnd); + eventHub.$on(EVT_PERF_MARK_DIFF_FILES_START, filesStart); + eventHub.$on(EVT_PERF_MARK_DIFF_FILES_END, filesEnd); + eventHub.$on(EVT_PERF_MARK_FIRST_DIFF_FILE_SHOWN, firstFile); + }, + deinstrument() { + eventHub.$off(EVT_PERF_MARK_FIRST_DIFF_FILE_SHOWN, firstFile); + eventHub.$off(EVT_PERF_MARK_DIFF_FILES_END, filesEnd); + eventHub.$off(EVT_PERF_MARK_DIFF_FILES_START, filesStart); + eventHub.$off(EVT_PERF_MARK_FILE_TREE_END, treeEnd); + eventHub.$off(EVT_PERF_MARK_FILE_TREE_START, treeStart); + }, +}; |