This repository was archived by the owner on Feb 4, 2022. It is now read-only.
File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const KillCursor = require ( '../connection/commands' ) . KillCursor ;
3
3
const GetMore = require ( '../connection/commands' ) . GetMore ;
4
- const process = require ( 'process' ) ;
4
+ const calculateDurationInMs = require ( '../utils' ) . calculateDurationInMs ;
5
5
6
6
/** Commands that we want to redact because of the sensitive nature of their contents */
7
7
const SENSITIVE_COMMANDS = new Set ( [
@@ -18,11 +18,6 @@ const SENSITIVE_COMMANDS = new Set([
18
18
19
19
// helper methods
20
20
const extractCommandName = command => Object . keys ( command ) [ 0 ] ;
21
- const calculateDurationInMs = started => {
22
- const hrtime = process . hrtime ( started ) ;
23
- return ( hrtime [ 0 ] * 1e9 + hrtime [ 1 ] ) / 1e6 ;
24
- } ;
25
-
26
21
const namespace = command => command . ns ;
27
22
const databaseName = command => command . ns . split ( '.' ) [ 0 ] ;
28
23
const collectionName = command => command . ns . split ( '.' ) [ 1 ] ;
Original file line number Diff line number Diff line change 2
2
3
3
const crypto = require ( 'crypto' ) ;
4
4
5
+ /**
6
+ * Generate a UUIDv4
7
+ */
5
8
const uuidV4 = ( ) => {
6
9
const result = crypto . randomBytes ( 16 ) ;
7
10
result [ 6 ] = ( result [ 6 ] & 0x0f ) | 0x40 ;
8
11
result [ 8 ] = ( result [ 8 ] & 0x3f ) | 0x80 ;
9
12
return result ;
10
13
} ;
11
14
15
+ /**
16
+ * Returns the duration calculated from two high resolution timers in milliseconds
17
+ *
18
+ * @param {Object } started A high resolution timestamp created from `process.hrtime()`
19
+ * @returns {Number } The duration in milliseconds
20
+ */
21
+ const calculateDurationInMs = started => {
22
+ const hrtime = process . hrtime ( started ) ;
23
+ return ( hrtime [ 0 ] * 1e9 + hrtime [ 1 ] ) / 1e6 ;
24
+ } ;
25
+
12
26
module . exports = {
13
- uuidV4 : uuidV4
27
+ uuidV4,
28
+ calculateDurationInMs
14
29
} ;
You can’t perform that action at this time.
0 commit comments