firebase-tools 11.0.0 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accountExporter.js +11 -4
- package/lib/accountImporter.js +93 -95
- package/lib/api.js +77 -218
- package/lib/apiv2.js +5 -4
- package/lib/appdistribution/client.js +23 -34
- package/lib/auth.js +72 -52
- package/lib/bin/firebase.js +42 -47
- package/lib/checkValidTargetFilters.js +36 -25
- package/lib/commands/appdistribution-distribute.js +2 -1
- package/lib/commands/appdistribution-testers-add.js +2 -1
- package/lib/commands/appdistribution-testers-remove.js +2 -1
- package/lib/commands/apps-android-sha-create.js +2 -1
- package/lib/commands/apps-android-sha-delete.js +2 -1
- package/lib/commands/apps-android-sha-list.js +2 -1
- package/lib/commands/apps-create.js +2 -1
- package/lib/commands/apps-list.js +2 -1
- package/lib/commands/apps-sdkconfig.js +2 -1
- package/lib/commands/auth-export.js +2 -1
- package/lib/commands/auth-import.js +7 -10
- package/lib/commands/crashlytics-symbols-upload.js +2 -1
- package/lib/commands/database-get.js +4 -3
- package/lib/commands/database-instances-create.js +2 -1
- package/lib/commands/database-instances-list.js +3 -3
- package/lib/commands/database-profile.js +4 -4
- package/lib/commands/database-push.js +4 -4
- package/lib/commands/database-remove.js +3 -3
- package/lib/commands/database-rules-canary.js +2 -1
- package/lib/commands/database-rules-get.js +2 -1
- package/lib/commands/database-rules-list.js +2 -1
- package/lib/commands/database-rules-release.js +2 -1
- package/lib/commands/database-rules-stage.js +2 -1
- package/lib/commands/database-set.js +3 -3
- package/lib/commands/database-settings-get.js +2 -1
- package/lib/commands/database-settings-set.js +2 -1
- package/lib/commands/database-update.js +2 -1
- package/lib/commands/deploy.js +26 -25
- package/lib/commands/emulators-exec.js +2 -1
- package/lib/commands/emulators-export.js +2 -1
- package/lib/commands/emulators-start.js +2 -1
- package/lib/commands/experimental-functions-shell.js +10 -8
- package/lib/commands/ext-configure.js +6 -1
- package/lib/commands/ext-dev-deprecate.js +2 -1
- package/lib/commands/ext-dev-emulators-exec.js +3 -2
- package/lib/commands/ext-dev-emulators-start.js +3 -2
- package/lib/commands/ext-dev-extension-delete.js +2 -1
- package/lib/commands/ext-dev-init.js +2 -1
- package/lib/commands/ext-dev-list.js +8 -8
- package/lib/commands/ext-dev-publish.js +2 -1
- package/lib/commands/ext-dev-register.js +2 -1
- package/lib/commands/ext-dev-undeprecate.js +2 -1
- package/lib/commands/ext-dev-unpublish.js +2 -1
- package/lib/commands/ext-dev-usage.js +2 -1
- package/lib/commands/ext-export.js +2 -1
- package/lib/commands/ext-info.js +14 -14
- package/lib/commands/ext-install.js +6 -1
- package/lib/commands/ext-list.js +2 -1
- package/lib/commands/ext-sources-create.js +2 -1
- package/lib/commands/ext-uninstall.js +7 -1
- package/lib/commands/ext-update.js +6 -1
- package/lib/commands/ext.js +4 -4
- package/lib/commands/firestore-delete.js +2 -1
- package/lib/commands/firestore-indexes-list.js +2 -1
- package/lib/commands/functions-config-clone.js +4 -3
- package/lib/commands/functions-config-export.js +2 -1
- package/lib/commands/functions-config-get.js +2 -1
- package/lib/commands/functions-config-set.js +2 -1
- package/lib/commands/functions-config-unset.js +2 -1
- package/lib/commands/functions-delete.js +3 -8
- package/lib/commands/functions-deletegcfartifacts.js +2 -1
- package/lib/commands/functions-list.js +2 -1
- package/lib/commands/functions-log.js +2 -1
- package/lib/commands/functions-secrets-access.js +2 -1
- package/lib/commands/functions-secrets-destroy.js +2 -1
- package/lib/commands/functions-secrets-get.js +2 -1
- package/lib/commands/functions-secrets-prune.js +2 -1
- package/lib/commands/functions-secrets-set.js +2 -1
- package/lib/commands/functions-shell.js +12 -10
- package/lib/commands/help.js +2 -1
- package/lib/commands/hosting-channel-create.js +2 -1
- package/lib/commands/hosting-channel-delete.js +2 -1
- package/lib/commands/hosting-channel-deploy.js +2 -1
- package/lib/commands/hosting-channel-list.js +2 -1
- package/lib/commands/hosting-channel-open.js +2 -1
- package/lib/commands/hosting-clone.js +2 -1
- package/lib/commands/hosting-disable.js +2 -1
- package/lib/commands/hosting-sites-create.js +2 -1
- package/lib/commands/hosting-sites-delete.js +2 -1
- package/lib/commands/hosting-sites-get.js +2 -1
- package/lib/commands/hosting-sites-list.js +2 -1
- package/lib/commands/index.js +23 -13
- package/lib/commands/init.js +47 -43
- package/lib/commands/login-add.js +2 -1
- package/lib/commands/login-ci.js +2 -1
- package/lib/commands/login-list.js +2 -1
- package/lib/commands/login-use.js +2 -1
- package/lib/commands/login.js +2 -1
- package/lib/commands/logout.js +2 -1
- package/lib/commands/open.js +7 -7
- package/lib/commands/projects-addfirebase.js +2 -1
- package/lib/commands/projects-create.js +2 -1
- package/lib/commands/projects-list.js +2 -1
- package/lib/commands/remoteconfig-get.js +2 -1
- package/lib/commands/remoteconfig-rollback.js +2 -1
- package/lib/commands/remoteconfig-versions-list.js +2 -1
- package/lib/commands/serve.js +30 -30
- package/lib/commands/setup-emulators-database.js +2 -1
- package/lib/commands/setup-emulators-firestore.js +2 -1
- package/lib/commands/setup-emulators-pubsub.js +2 -1
- package/lib/commands/setup-emulators-storage.js +2 -1
- package/lib/commands/setup-emulators-ui.js +2 -1
- package/lib/commands/target-apply.js +2 -1
- package/lib/commands/target-clear.js +2 -1
- package/lib/commands/target-remove.js +2 -1
- package/lib/commands/target.js +2 -1
- package/lib/commands/use.js +54 -53
- package/lib/config.js +7 -6
- package/lib/deploy/database/deploy.js +3 -2
- package/lib/deploy/database/index.js +8 -5
- package/lib/deploy/database/prepare.js +22 -20
- package/lib/deploy/database/release.js +12 -9
- package/lib/deploy/extensions/secrets.js +3 -3
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/build.js +33 -20
- package/lib/deploy/functions/ensure.js +1 -11
- package/lib/deploy/functions/prepare.js +3 -13
- package/lib/deploy/functions/prepareFunctionsUpload.js +2 -3
- package/lib/deploy/functions/release/fabricator.js +0 -1
- package/lib/deploy/functions/release/index.js +1 -5
- package/lib/deploy/functions/runtimes/discovery/index.js +18 -3
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +188 -54
- package/lib/deploy/functions/runtimes/golang/index.js +2 -22
- package/lib/deploy/functions/runtimes/node/index.js +3 -7
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +15 -3
- package/lib/deploy/functions/services/database.js +14 -0
- package/lib/deploy/functions/services/index.js +14 -0
- package/lib/deploy/index.js +3 -3
- package/lib/deploy/lifecycleHooks.js +27 -27
- package/lib/deploy/remoteconfig/functions.js +18 -14
- package/lib/deploy/remoteconfig/prepare.js +2 -2
- package/lib/deploy/storage/prepare.js +1 -1
- package/lib/emulator/auth/apiSpec.js +14 -46
- package/lib/emulator/auth/index.js +1 -1
- package/lib/emulator/auth/operations.js +342 -93
- package/lib/emulator/auth/server.js +2 -2
- package/lib/emulator/auth/state.js +34 -32
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/constants.js +1 -1
- package/lib/emulator/controller.js +7 -6
- package/lib/emulator/databaseEmulator.js +11 -9
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/events/types.js +2 -3
- package/lib/emulator/firestoreEmulator.js +12 -14
- package/lib/emulator/functionsEmulator.js +65 -77
- package/lib/emulator/functionsEmulatorRuntime.js +7 -7
- package/lib/emulator/hostingEmulator.js +1 -1
- package/lib/emulator/hub.js +1 -1
- package/lib/emulator/hubClient.js +11 -22
- package/lib/emulator/hubExport.js +26 -16
- package/lib/emulator/loggingEmulator.js +1 -1
- package/lib/emulator/pubsubEmulator.js +1 -1
- package/lib/emulator/storage/crc.js +4 -4
- package/lib/emulator/storage/index.js +1 -1
- package/lib/emulator/types.js +1 -1
- package/lib/errorOut.js +2 -2
- package/lib/extensions/askUserForConsent.js +1 -2
- package/lib/extensions/askUserForParam.js +15 -18
- package/lib/extensions/emulator/optionsHelper.js +4 -4
- package/lib/extensions/extensionsApi.js +1 -22
- package/lib/extensions/extensionsHelper.js +6 -6
- package/lib/extensions/listExtensions.js +9 -10
- package/lib/extensions/manifest.js +2 -2
- package/lib/extensions/resolveSource.js +11 -7
- package/lib/extensions/secretsUtils.js +3 -3
- package/lib/extensions/types.js +24 -0
- package/lib/extensions/updateHelper.js +1 -1
- package/lib/extensions/utils.js +1 -2
- package/lib/extensions/warnings.js +3 -3
- package/lib/firestore/checkDatabaseType.js +4 -5
- package/lib/firestore/encodeFirestoreValue.js +11 -8
- package/lib/firestore/indexes.js +17 -34
- package/lib/fsAsync.js +3 -3
- package/lib/functions/events/v2.js +7 -1
- package/lib/functionsConfig.js +17 -14
- package/lib/functionsConfigClone.js +46 -46
- package/lib/gcp/cloudfunctions.js +2 -15
- package/lib/gcp/cloudfunctionsv2.js +17 -2
- package/lib/gcp/iam.js +1 -1
- package/lib/gcp/index.js +10 -10
- package/lib/gcp/rules.js +1 -1
- package/lib/gcp/runtimeconfig.js +45 -47
- package/lib/gcp/storage.js +2 -4
- package/lib/hosting/cloudRunProxy.js +19 -15
- package/lib/hosting/proxy.js +1 -1
- package/lib/index.js +29 -28
- package/lib/init/features/database.js +11 -5
- package/lib/init/features/functions/index.js +1 -1
- package/lib/init/features/functions/javascript.js +23 -20
- package/lib/init/features/functions/npm-dependencies.js +17 -14
- package/lib/init/features/functions/typescript.js +27 -24
- package/lib/init/features/hosting/github.js +6 -5
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/loadCJSON.js +9 -6
- package/lib/localFunction.js +4 -4
- package/lib/logError.js +15 -12
- package/lib/management/apps.js +47 -43
- package/lib/management/database.js +33 -31
- package/lib/management/projects.js +13 -7
- package/lib/parseBoltRules.js +15 -14
- package/lib/previews.js +1 -1
- package/lib/profileReport.js +504 -512
- package/lib/profiler.js +4 -4
- package/lib/prompt.js +1 -2
- package/lib/rc.js +1 -1
- package/lib/requireAuth.js +0 -1
- package/lib/responseToError.js +8 -5
- package/lib/rtdb.js +31 -29
- package/lib/rulesDeploy.js +2 -2
- package/lib/scopes.js +9 -9
- package/lib/serve/index.js +4 -5
- package/lib/utils.js +30 -6
- package/npm-shrinkwrap.json +877 -279
- package/package.json +19 -16
- package/standalone/package.json +1 -1
package/lib/profileReport.js
CHANGED
|
@@ -1,41 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileReport = exports.extractReadableIndex = exports.formatBytes = exports.formatNumber = exports.pathString = exports.extractJSON = void 0;
|
|
4
|
+
const clc = require("cli-color");
|
|
5
|
+
const Table = require("cli-table");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const _ = require("lodash");
|
|
8
|
+
const readline = require("readline");
|
|
9
|
+
const error_1 = require("./error");
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
const DATA_LINE_REGEX = /^data: /;
|
|
12
|
+
const BANDWIDTH_NOTE = "NOTE: The numbers reported here are only estimates of the data" +
|
|
11
13
|
" payloads from read operations. They are NOT a valid measure of your bandwidth bill.";
|
|
12
|
-
|
|
14
|
+
const SPEED_NOTE = "NOTE: Speeds are reported at millisecond resolution and" +
|
|
13
15
|
" are not the latencies that clients will see. Pending times" +
|
|
14
16
|
" are also reported at millisecond resolution. They approximate" +
|
|
15
17
|
" the interval of time between the instant a request is received" +
|
|
16
18
|
" and the instant it executes.";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.tempFile = tmpFile;
|
|
21
|
-
this.output = outStream;
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.state = {
|
|
24
|
-
outband: {},
|
|
25
|
-
inband: {},
|
|
26
|
-
writeSpeed: {},
|
|
27
|
-
broadcastSpeed: {},
|
|
28
|
-
readSpeed: {},
|
|
29
|
-
connectSpeed: {},
|
|
30
|
-
disconnectSpeed: {},
|
|
31
|
-
unlistenSpeed: {},
|
|
32
|
-
unindexed: {},
|
|
33
|
-
startTime: 0,
|
|
34
|
-
endTime: 0,
|
|
35
|
-
opCount: 0,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
ProfileReport.extractJSON = function (line, input) {
|
|
19
|
+
const COLLAPSE_THRESHOLD = 25;
|
|
20
|
+
const COLLAPSE_WILDCARD = ["$wildcard"];
|
|
21
|
+
function extractJSON(line, input) {
|
|
39
22
|
if (!input && !DATA_LINE_REGEX.test(line)) {
|
|
40
23
|
return null;
|
|
41
24
|
}
|
|
@@ -48,536 +31,545 @@ ProfileReport.extractJSON = function (line, input) {
|
|
|
48
31
|
catch (e) {
|
|
49
32
|
return null;
|
|
50
33
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
34
|
+
}
|
|
35
|
+
exports.extractJSON = extractJSON;
|
|
36
|
+
function pathString(path) {
|
|
37
|
+
return `/${path ? path.join("/") : ""}`;
|
|
38
|
+
}
|
|
39
|
+
exports.pathString = pathString;
|
|
40
|
+
function formatNumber(num) {
|
|
41
|
+
const parts = num.toFixed(2).split(".");
|
|
57
42
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
58
43
|
if (+parts[1] === 0) {
|
|
59
44
|
return parts[0];
|
|
60
45
|
}
|
|
61
46
|
return parts.join(".");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
}
|
|
48
|
+
exports.formatNumber = formatNumber;
|
|
49
|
+
function formatBytes(bytes) {
|
|
50
|
+
const threshold = 1000;
|
|
65
51
|
if (Math.round(bytes) < threshold) {
|
|
66
52
|
return bytes + " B";
|
|
67
53
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
const units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
55
|
+
let u = -1;
|
|
56
|
+
let formattedBytes = bytes;
|
|
71
57
|
do {
|
|
72
58
|
formattedBytes /= threshold;
|
|
73
59
|
u++;
|
|
74
60
|
} while (Math.abs(formattedBytes) >= threshold && u < units.length - 1);
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
return formatNumber(formattedBytes) + " " + units[u];
|
|
62
|
+
}
|
|
63
|
+
exports.formatBytes = formatBytes;
|
|
64
|
+
function extractReadableIndex(query) {
|
|
65
|
+
if (query.orderBy) {
|
|
79
66
|
return query.orderBy;
|
|
80
67
|
}
|
|
81
|
-
|
|
68
|
+
const indexPath = _.get(query, "index.path");
|
|
82
69
|
if (indexPath) {
|
|
83
|
-
return
|
|
70
|
+
return pathString(indexPath);
|
|
84
71
|
}
|
|
85
72
|
return ".value";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
73
|
+
}
|
|
74
|
+
exports.extractReadableIndex = extractReadableIndex;
|
|
75
|
+
class ProfileReport {
|
|
76
|
+
constructor(tmpFile, outStream, options = {}) {
|
|
77
|
+
this.tempFile = tmpFile;
|
|
78
|
+
this.output = outStream;
|
|
79
|
+
this.options = options;
|
|
80
|
+
this.state = {
|
|
81
|
+
outband: {},
|
|
82
|
+
inband: {},
|
|
83
|
+
writeSpeed: {},
|
|
84
|
+
broadcastSpeed: {},
|
|
85
|
+
readSpeed: {},
|
|
86
|
+
connectSpeed: {},
|
|
87
|
+
disconnectSpeed: {},
|
|
88
|
+
unlistenSpeed: {},
|
|
89
|
+
unindexed: {},
|
|
90
|
+
startTime: 0,
|
|
91
|
+
endTime: 0,
|
|
92
|
+
opCount: 0,
|
|
101
93
|
};
|
|
102
94
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
opStats.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
collectUnindexed(data, path) {
|
|
96
|
+
if (!data.unIndexed) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!this.state.unindexed.path) {
|
|
100
|
+
this.state.unindexed[path] = {};
|
|
101
|
+
}
|
|
102
|
+
const pathNode = this.state.unindexed[path];
|
|
103
|
+
const query = data.querySet[0];
|
|
104
|
+
const index = JSON.stringify(query.index);
|
|
105
|
+
if (!pathNode[index]) {
|
|
106
|
+
pathNode[index] = {
|
|
107
|
+
times: 0,
|
|
108
|
+
query: query,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const indexNode = pathNode[index];
|
|
112
|
+
indexNode.times += 1;
|
|
113
|
+
}
|
|
114
|
+
collectSpeedUnpathed(data, opStats) {
|
|
115
|
+
if (Object.keys(opStats).length === 0) {
|
|
116
|
+
opStats.times = 0;
|
|
117
|
+
opStats.millis = 0;
|
|
118
|
+
opStats.pendingCount = 0;
|
|
119
|
+
opStats.pendingTime = 0;
|
|
120
|
+
opStats.rejected = 0;
|
|
121
|
+
}
|
|
122
|
+
opStats.times += 1;
|
|
123
|
+
if (data.hasOwnProperty("millis")) {
|
|
124
|
+
opStats.millis += data.millis;
|
|
125
|
+
}
|
|
126
|
+
if (data.hasOwnProperty("pendingTime")) {
|
|
127
|
+
opStats.pendingCount++;
|
|
128
|
+
opStats.pendingTime += data.pendingTime;
|
|
129
|
+
}
|
|
130
|
+
if (data.allowed === false) {
|
|
131
|
+
opStats.rejected += 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
collectSpeed(data, path, opType) {
|
|
135
|
+
if (!opType[path]) {
|
|
136
|
+
opType[path] = {
|
|
137
|
+
times: 0,
|
|
138
|
+
millis: 0,
|
|
139
|
+
pendingCount: 0,
|
|
140
|
+
pendingTime: 0,
|
|
141
|
+
rejected: 0,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const node = opType[path];
|
|
145
|
+
node.times += 1;
|
|
146
|
+
if (data.hasOwnProperty("millis")) {
|
|
147
|
+
node.millis += data.millis;
|
|
148
|
+
}
|
|
149
|
+
if (data.hasOwnProperty("pendingTime")) {
|
|
150
|
+
node.pendingCount++;
|
|
151
|
+
node.pendingTime += data.pendingTime;
|
|
152
|
+
}
|
|
153
|
+
if (data.allowed === false) {
|
|
154
|
+
node.rejected += 1;
|
|
155
|
+
}
|
|
135
156
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
collectBandwidth(bytes, path, direction) {
|
|
158
|
+
if (!direction[path]) {
|
|
159
|
+
direction[path] = {
|
|
160
|
+
times: 0,
|
|
161
|
+
bytes: 0,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const node = direction[path];
|
|
165
|
+
node.times += 1;
|
|
166
|
+
node.bytes += bytes;
|
|
140
167
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
collectRead(data, path, bytes) {
|
|
169
|
+
this.collectSpeed(data, path, this.state.readSpeed);
|
|
170
|
+
this.collectBandwidth(bytes, path, this.state.outband);
|
|
144
171
|
}
|
|
145
|
-
|
|
146
|
-
|
|
172
|
+
collectBroadcast(data, path, bytes) {
|
|
173
|
+
this.collectSpeed(data, path, this.state.broadcastSpeed);
|
|
174
|
+
this.collectBandwidth(bytes, path, this.state.outband);
|
|
147
175
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
176
|
+
collectUnlisten(data, path) {
|
|
177
|
+
this.collectSpeed(data, path, this.state.unlistenSpeed);
|
|
178
|
+
}
|
|
179
|
+
collectConnect(data) {
|
|
180
|
+
this.collectSpeedUnpathed(data, this.state.connectSpeed);
|
|
181
|
+
}
|
|
182
|
+
collectDisconnect(data) {
|
|
183
|
+
this.collectSpeedUnpathed(data, this.state.disconnectSpeed);
|
|
184
|
+
}
|
|
185
|
+
collectWrite(data, path, bytes) {
|
|
186
|
+
this.collectSpeed(data, path, this.state.writeSpeed);
|
|
187
|
+
this.collectBandwidth(bytes, path, this.state.inband);
|
|
188
|
+
}
|
|
189
|
+
processOperation(data) {
|
|
190
|
+
if (!this.state.startTime) {
|
|
191
|
+
this.state.startTime = data.timestamp;
|
|
192
|
+
}
|
|
193
|
+
this.state.endTime = data.timestamp;
|
|
194
|
+
const path = pathString(data.path);
|
|
195
|
+
this.state.opCount++;
|
|
196
|
+
switch (data.name) {
|
|
197
|
+
case "concurrent-connect":
|
|
198
|
+
this.collectConnect(data);
|
|
199
|
+
break;
|
|
200
|
+
case "concurrent-disconnect":
|
|
201
|
+
this.collectDisconnect(data);
|
|
202
|
+
break;
|
|
203
|
+
case "realtime-read":
|
|
204
|
+
this.collectRead(data, path, data.bytes);
|
|
205
|
+
break;
|
|
206
|
+
case "realtime-write":
|
|
207
|
+
this.collectWrite(data, path, data.bytes);
|
|
208
|
+
break;
|
|
209
|
+
case "realtime-transaction":
|
|
210
|
+
this.collectWrite(data, path, data.bytes);
|
|
211
|
+
break;
|
|
212
|
+
case "realtime-update":
|
|
213
|
+
this.collectWrite(data, path, data.bytes);
|
|
214
|
+
break;
|
|
215
|
+
case "listener-listen":
|
|
216
|
+
this.collectRead(data, path, data.bytes);
|
|
217
|
+
this.collectUnindexed(data, path);
|
|
218
|
+
break;
|
|
219
|
+
case "listener-broadcast":
|
|
220
|
+
this.collectBroadcast(data, path, data.bytes);
|
|
221
|
+
break;
|
|
222
|
+
case "listener-unlisten":
|
|
223
|
+
this.collectUnlisten(data, path);
|
|
224
|
+
break;
|
|
225
|
+
case "rest-read":
|
|
226
|
+
this.collectRead(data, path, data.bytes);
|
|
227
|
+
break;
|
|
228
|
+
case "rest-write":
|
|
229
|
+
this.collectWrite(data, path, data.bytes);
|
|
230
|
+
break;
|
|
231
|
+
case "rest-update":
|
|
232
|
+
this.collectWrite(data, path, data.bytes);
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
155
237
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
};
|
|
164
|
-
ProfileReport.prototype.collectBroadcast = function (data, path, bytes) {
|
|
165
|
-
this.collectSpeed(data, path, this.state.broadcastSpeed);
|
|
166
|
-
this.collectBandwidth(bytes, path, this.state.outband);
|
|
167
|
-
};
|
|
168
|
-
ProfileReport.prototype.collectUnlisten = function (data, path) {
|
|
169
|
-
this.collectSpeed(data, path, this.state.unlistenSpeed);
|
|
170
|
-
};
|
|
171
|
-
ProfileReport.prototype.collectConnect = function (data) {
|
|
172
|
-
this.collectSpeedUnpathed(data, this.state.connectSpeed);
|
|
173
|
-
};
|
|
174
|
-
ProfileReport.prototype.collectDisconnect = function (data) {
|
|
175
|
-
this.collectSpeedUnpathed(data, this.state.disconnectSpeed);
|
|
176
|
-
};
|
|
177
|
-
ProfileReport.prototype.collectWrite = function (data, path, bytes) {
|
|
178
|
-
this.collectSpeed(data, path, this.state.writeSpeed);
|
|
179
|
-
this.collectBandwidth(bytes, path, this.state.inband);
|
|
180
|
-
};
|
|
181
|
-
ProfileReport.prototype.processOperation = function (data) {
|
|
182
|
-
if (!this.state.startTime) {
|
|
183
|
-
this.state.startTime = data.timestamp;
|
|
184
|
-
}
|
|
185
|
-
this.state.endTime = data.timestamp;
|
|
186
|
-
var path = ProfileReport.pathString(data.path);
|
|
187
|
-
this.state.opCount++;
|
|
188
|
-
switch (data.name) {
|
|
189
|
-
case "concurrent-connect":
|
|
190
|
-
this.collectConnect(data);
|
|
191
|
-
break;
|
|
192
|
-
case "concurrent-disconnect":
|
|
193
|
-
this.collectDisconnect(data);
|
|
194
|
-
break;
|
|
195
|
-
case "realtime-read":
|
|
196
|
-
this.collectRead(data, path, data.bytes);
|
|
197
|
-
break;
|
|
198
|
-
case "realtime-write":
|
|
199
|
-
this.collectWrite(data, path, data.bytes);
|
|
200
|
-
break;
|
|
201
|
-
case "realtime-transaction":
|
|
202
|
-
this.collectWrite(data, path, data.bytes);
|
|
203
|
-
break;
|
|
204
|
-
case "realtime-update":
|
|
205
|
-
this.collectWrite(data, path, data.bytes);
|
|
206
|
-
break;
|
|
207
|
-
case "listener-listen":
|
|
208
|
-
this.collectRead(data, path, data.bytes);
|
|
209
|
-
this.collectUnindexed(data, path);
|
|
210
|
-
break;
|
|
211
|
-
case "listener-broadcast":
|
|
212
|
-
this.collectBroadcast(data, path, data.bytes);
|
|
213
|
-
break;
|
|
214
|
-
case "listener-unlisten":
|
|
215
|
-
this.collectUnlisten(data, path);
|
|
216
|
-
break;
|
|
217
|
-
case "rest-read":
|
|
218
|
-
this.collectRead(data, path, data.bytes);
|
|
219
|
-
break;
|
|
220
|
-
case "rest-write":
|
|
221
|
-
this.collectWrite(data, path, data.bytes);
|
|
222
|
-
break;
|
|
223
|
-
case "rest-update":
|
|
224
|
-
this.collectWrite(data, path, data.bytes);
|
|
225
|
-
break;
|
|
226
|
-
default:
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
ProfileReport.prototype.collapsePaths = function (pathedObject, combiner, pathIndex) {
|
|
231
|
-
if (!this.options.collapse) {
|
|
232
|
-
return pathedObject;
|
|
233
|
-
}
|
|
234
|
-
if (_.isUndefined(pathIndex)) {
|
|
235
|
-
pathIndex = 1;
|
|
236
|
-
}
|
|
237
|
-
var allSegments = _.keys(pathedObject).map(function (path) {
|
|
238
|
-
return path.split("/").filter(function (s) {
|
|
239
|
-
return s !== "";
|
|
238
|
+
collapsePaths(pathedObject, combiner, pathIndex = 1) {
|
|
239
|
+
if (!this.options.collapse) {
|
|
240
|
+
return pathedObject;
|
|
241
|
+
}
|
|
242
|
+
const allSegments = Object.keys(pathedObject).map((path) => {
|
|
243
|
+
return path.split("/").filter((s) => {
|
|
244
|
+
return s !== "";
|
|
245
|
+
});
|
|
240
246
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
247
|
+
const pathSegments = allSegments.filter((segments) => {
|
|
248
|
+
return segments.length > pathIndex;
|
|
249
|
+
});
|
|
250
|
+
const otherSegments = allSegments.filter((segments) => {
|
|
251
|
+
return segments.length <= pathIndex;
|
|
252
|
+
});
|
|
253
|
+
if (pathSegments.length === 0) {
|
|
254
|
+
return pathedObject;
|
|
255
|
+
}
|
|
256
|
+
const prefixes = {};
|
|
257
|
+
pathSegments.forEach((segments) => {
|
|
258
|
+
const prefixPath = pathString(segments.slice(0, pathIndex));
|
|
259
|
+
const prefixCount = _.get(prefixes, prefixPath, new Set());
|
|
260
|
+
prefixes[prefixPath] = prefixCount.add(segments[pathIndex]);
|
|
261
|
+
});
|
|
262
|
+
const collapsedObject = {};
|
|
263
|
+
pathSegments.forEach((segments) => {
|
|
264
|
+
const prefix = segments.slice(0, pathIndex);
|
|
265
|
+
const prefixPath = pathString(prefix);
|
|
266
|
+
const prefixCount = _.get(prefixes, prefixPath);
|
|
267
|
+
const originalPath = pathString(segments);
|
|
268
|
+
if (prefixCount.size >= COLLAPSE_THRESHOLD) {
|
|
269
|
+
const tail = segments.slice(pathIndex + 1);
|
|
270
|
+
const collapsedPath = pathString(prefix.concat(COLLAPSE_WILDCARD).concat(tail));
|
|
271
|
+
const currentValue = collapsedObject[collapsedPath];
|
|
272
|
+
if (currentValue) {
|
|
273
|
+
collapsedObject[collapsedPath] = combiner(currentValue, pathedObject[originalPath]);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
collapsedObject[collapsedPath] = pathedObject[originalPath];
|
|
277
|
+
}
|
|
269
278
|
}
|
|
270
279
|
else {
|
|
271
|
-
collapsedObject[
|
|
280
|
+
collapsedObject[originalPath] = pathedObject[originalPath];
|
|
272
281
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
282
|
+
});
|
|
283
|
+
otherSegments.forEach((segments) => {
|
|
284
|
+
const originalPath = pathString(segments);
|
|
275
285
|
collapsedObject[originalPath] = pathedObject[originalPath];
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
286
|
+
});
|
|
287
|
+
return this.collapsePaths(collapsedObject, combiner, pathIndex + 1);
|
|
288
|
+
}
|
|
289
|
+
renderUnindexedData() {
|
|
290
|
+
const table = new Table({
|
|
291
|
+
head: ["Path", "Index", "Count"],
|
|
292
|
+
style: {
|
|
293
|
+
head: this.options.isFile ? [] : ["yellow"],
|
|
294
|
+
border: this.options.isFile ? [] : ["grey"],
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
const unindexed = this.collapsePaths(this.state.unindexed, (u1, u2) => {
|
|
298
|
+
_.mergeWith(u1, u2, (p1, p2) => {
|
|
299
|
+
return {
|
|
300
|
+
times: p1.times + p2.times,
|
|
301
|
+
query: p1.query,
|
|
302
|
+
};
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
const paths = Object.keys(unindexed);
|
|
306
|
+
paths.forEach((path) => {
|
|
307
|
+
const indices = Object.keys(unindexed[path]);
|
|
308
|
+
indices.forEach((index) => {
|
|
309
|
+
const data = unindexed[path][index];
|
|
310
|
+
const row = [path, extractReadableIndex(data.query), formatNumber(data.times)];
|
|
311
|
+
table.push(row);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
return table;
|
|
315
|
+
}
|
|
316
|
+
renderBandwidth(pureData) {
|
|
317
|
+
const table = new Table({
|
|
318
|
+
head: ["Path", "Total", "Count", "Average"],
|
|
319
|
+
style: {
|
|
320
|
+
head: this.options.isFile ? [] : ["yellow"],
|
|
321
|
+
border: this.options.isFile ? [] : ["grey"],
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
const data = this.collapsePaths(pureData, (b1, b2) => {
|
|
294
325
|
return {
|
|
295
|
-
|
|
296
|
-
|
|
326
|
+
bytes: b1.bytes + b2.bytes,
|
|
327
|
+
times: b1.times + b2.times,
|
|
297
328
|
};
|
|
298
329
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
indices.forEach(function (index) {
|
|
304
|
-
var data = unindexed[path][index];
|
|
305
|
-
var row = [
|
|
330
|
+
const paths = _.orderBy(Object.keys(data), [(p) => data[p].bytes], ["desc"]);
|
|
331
|
+
paths.forEach((path) => {
|
|
332
|
+
const bandwidth = data[path];
|
|
333
|
+
const row = [
|
|
306
334
|
path,
|
|
307
|
-
|
|
308
|
-
|
|
335
|
+
formatBytes(bandwidth.bytes),
|
|
336
|
+
formatNumber(bandwidth.times),
|
|
337
|
+
formatBytes(bandwidth.bytes / bandwidth.times),
|
|
309
338
|
];
|
|
310
339
|
table.push(row);
|
|
311
340
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
323
|
-
var data = this.collapsePaths(pureData, function (b1, b2) {
|
|
324
|
-
return {
|
|
325
|
-
bytes: b1.bytes + b2.bytes,
|
|
326
|
-
times: b1.times + b2.times,
|
|
327
|
-
};
|
|
328
|
-
});
|
|
329
|
-
var paths = _.keys(data);
|
|
330
|
-
paths = _.orderBy(paths, function (path) {
|
|
331
|
-
var bandwidth = data[path];
|
|
332
|
-
return bandwidth.bytes;
|
|
333
|
-
}, ["desc"]);
|
|
334
|
-
paths.forEach(function (path) {
|
|
335
|
-
var bandwidth = data[path];
|
|
336
|
-
var row = [
|
|
337
|
-
path,
|
|
338
|
-
ProfileReport.formatBytes(bandwidth.bytes),
|
|
339
|
-
ProfileReport.formatNumber(bandwidth.times),
|
|
340
|
-
ProfileReport.formatBytes(bandwidth.bytes / bandwidth.times),
|
|
341
|
-
];
|
|
342
|
-
table.push(row);
|
|
343
|
-
});
|
|
344
|
-
return table;
|
|
345
|
-
};
|
|
346
|
-
ProfileReport.prototype.renderOutgoingBandwidth = function () {
|
|
347
|
-
return this.renderBandwidth(this.state.outband);
|
|
348
|
-
};
|
|
349
|
-
ProfileReport.prototype.renderIncomingBandwidth = function () {
|
|
350
|
-
return this.renderBandwidth(this.state.inband);
|
|
351
|
-
};
|
|
352
|
-
ProfileReport.prototype.renderUnpathedOperationSpeed = function (speedData, hasSecurity) {
|
|
353
|
-
var head = ["Count", "Average Execution Speed", "Average Pending Time"];
|
|
354
|
-
if (hasSecurity) {
|
|
355
|
-
head.push("Permission Denied");
|
|
356
|
-
}
|
|
357
|
-
var table = new Table({
|
|
358
|
-
head: head,
|
|
359
|
-
style: {
|
|
360
|
-
head: this.options.isFile ? [] : ["yellow"],
|
|
361
|
-
border: this.options.isFile ? [] : ["grey"],
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
if (Object.keys(speedData).length > 0) {
|
|
365
|
-
var row = [
|
|
366
|
-
speedData.times,
|
|
367
|
-
ProfileReport.formatNumber(speedData.millis / speedData.times) + " ms",
|
|
368
|
-
ProfileReport.formatNumber(speedData.pendingCount === 0 ? 0 : speedData.pendingTime / speedData.pendingCount) + " ms",
|
|
369
|
-
];
|
|
341
|
+
return table;
|
|
342
|
+
}
|
|
343
|
+
renderOutgoingBandwidth() {
|
|
344
|
+
return this.renderBandwidth(this.state.outband);
|
|
345
|
+
}
|
|
346
|
+
renderIncomingBandwidth() {
|
|
347
|
+
return this.renderBandwidth(this.state.inband);
|
|
348
|
+
}
|
|
349
|
+
renderUnpathedOperationSpeed(speedData, hasSecurity = false) {
|
|
350
|
+
const head = ["Count", "Average Execution Speed", "Average Pending Time"];
|
|
370
351
|
if (hasSecurity) {
|
|
371
|
-
|
|
352
|
+
head.push("Permission Denied");
|
|
372
353
|
}
|
|
373
|
-
table
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
rejected: s1.rejected + s2.rejected,
|
|
396
|
-
};
|
|
397
|
-
});
|
|
398
|
-
var paths = _.keys(data);
|
|
399
|
-
paths = _.orderBy(paths, function (path) {
|
|
400
|
-
var speed = data[path];
|
|
401
|
-
return speed.millis / speed.times;
|
|
402
|
-
}, ["desc"]);
|
|
403
|
-
paths.forEach(function (path) {
|
|
404
|
-
var speed = data[path];
|
|
405
|
-
var row = [
|
|
406
|
-
path,
|
|
407
|
-
speed.times,
|
|
408
|
-
ProfileReport.formatNumber(speed.millis / speed.times) + " ms",
|
|
409
|
-
ProfileReport.formatNumber(speed.pendingCount === 0 ? 0 : speed.pendingTime / speed.pendingCount) + " ms",
|
|
410
|
-
];
|
|
354
|
+
const table = new Table({
|
|
355
|
+
head: head,
|
|
356
|
+
style: {
|
|
357
|
+
head: this.options.isFile ? [] : ["yellow"],
|
|
358
|
+
border: this.options.isFile ? [] : ["grey"],
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
if (Object.keys(speedData).length > 0) {
|
|
362
|
+
const row = [
|
|
363
|
+
speedData.times,
|
|
364
|
+
formatNumber(speedData.millis / speedData.times) + " ms",
|
|
365
|
+
formatNumber(speedData.pendingCount === 0 ? 0 : speedData.pendingTime / speedData.pendingCount) + " ms",
|
|
366
|
+
];
|
|
367
|
+
if (hasSecurity) {
|
|
368
|
+
row.push(formatNumber(speedData.rejected));
|
|
369
|
+
}
|
|
370
|
+
table.push(row);
|
|
371
|
+
}
|
|
372
|
+
return table;
|
|
373
|
+
}
|
|
374
|
+
renderOperationSpeed(pureData, hasSecurity = false) {
|
|
375
|
+
const head = ["Path", "Count", "Average Execution Speed", "Average Pending Time"];
|
|
411
376
|
if (hasSecurity) {
|
|
412
|
-
|
|
377
|
+
head.push("Permission Denied");
|
|
413
378
|
}
|
|
414
|
-
table
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
};
|
|
421
|
-
ProfileReport.prototype.renderWriteSpeed = function () {
|
|
422
|
-
return this.renderOperationSpeed(this.state.writeSpeed, true);
|
|
423
|
-
};
|
|
424
|
-
ProfileReport.prototype.renderBroadcastSpeed = function () {
|
|
425
|
-
return this.renderOperationSpeed(this.state.broadcastSpeed, false);
|
|
426
|
-
};
|
|
427
|
-
ProfileReport.prototype.renderConnectSpeed = function () {
|
|
428
|
-
return this.renderUnpathedOperationSpeed(this.state.connectSpeed, false);
|
|
429
|
-
};
|
|
430
|
-
ProfileReport.prototype.renderDisconnectSpeed = function () {
|
|
431
|
-
return this.renderUnpathedOperationSpeed(this.state.disconnectSpeed, false);
|
|
432
|
-
};
|
|
433
|
-
ProfileReport.prototype.renderUnlistenSpeed = function () {
|
|
434
|
-
return this.renderOperationSpeed(this.state.unlistenSpeed, false);
|
|
435
|
-
};
|
|
436
|
-
ProfileReport.prototype.parse = function (onLine, onClose) {
|
|
437
|
-
var isFile = this.options.isFile;
|
|
438
|
-
var tmpFile = this.tempFile;
|
|
439
|
-
var outStream = this.output;
|
|
440
|
-
var isInput = this.options.isInput;
|
|
441
|
-
return new Promise(function (resolve, reject) {
|
|
442
|
-
var rl = readline.createInterface({
|
|
443
|
-
input: fs.createReadStream(tmpFile),
|
|
379
|
+
const table = new Table({
|
|
380
|
+
head: head,
|
|
381
|
+
style: {
|
|
382
|
+
head: this.options.isFile ? [] : ["yellow"],
|
|
383
|
+
border: this.options.isFile ? [] : ["grey"],
|
|
384
|
+
},
|
|
444
385
|
});
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
386
|
+
const data = this.collapsePaths(pureData, (s1, s2) => {
|
|
387
|
+
return {
|
|
388
|
+
times: s1.times + s2.times,
|
|
389
|
+
millis: s1.millis + s2.millis,
|
|
390
|
+
pendingCount: s1.pendingCount + s2.pendingCount,
|
|
391
|
+
pendingTime: s1.pendingTime + s2.pendingTime,
|
|
392
|
+
rejected: s1.rejected + s2.rejected,
|
|
393
|
+
};
|
|
452
394
|
});
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
395
|
+
let paths = Object.keys(data);
|
|
396
|
+
paths = _.orderBy(paths, (path) => {
|
|
397
|
+
const speed = data[path];
|
|
398
|
+
return speed.millis / speed.times;
|
|
399
|
+
}, ["desc"]);
|
|
400
|
+
paths.forEach((path) => {
|
|
401
|
+
const speed = data[path];
|
|
402
|
+
const row = [
|
|
403
|
+
path,
|
|
404
|
+
speed.times,
|
|
405
|
+
formatNumber(speed.millis / speed.times) + " ms",
|
|
406
|
+
formatNumber(speed.pendingCount === 0 ? 0 : speed.pendingTime / speed.pendingCount) + " ms",
|
|
407
|
+
];
|
|
408
|
+
if (hasSecurity) {
|
|
409
|
+
row.push(formatNumber(speed.rejected));
|
|
456
410
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
411
|
+
table.push(row);
|
|
412
|
+
});
|
|
413
|
+
return table;
|
|
414
|
+
}
|
|
415
|
+
renderReadSpeed() {
|
|
416
|
+
return this.renderOperationSpeed(this.state.readSpeed, true);
|
|
417
|
+
}
|
|
418
|
+
renderWriteSpeed() {
|
|
419
|
+
return this.renderOperationSpeed(this.state.writeSpeed, true);
|
|
420
|
+
}
|
|
421
|
+
renderBroadcastSpeed() {
|
|
422
|
+
return this.renderOperationSpeed(this.state.broadcastSpeed, false);
|
|
423
|
+
}
|
|
424
|
+
renderConnectSpeed() {
|
|
425
|
+
return this.renderUnpathedOperationSpeed(this.state.connectSpeed, false);
|
|
426
|
+
}
|
|
427
|
+
renderDisconnectSpeed() {
|
|
428
|
+
return this.renderUnpathedOperationSpeed(this.state.disconnectSpeed, false);
|
|
429
|
+
}
|
|
430
|
+
renderUnlistenSpeed() {
|
|
431
|
+
return this.renderOperationSpeed(this.state.unlistenSpeed, false);
|
|
432
|
+
}
|
|
433
|
+
async parse(onLine, onClose) {
|
|
434
|
+
const isFile = this.options.isFile;
|
|
435
|
+
const tmpFile = this.tempFile;
|
|
436
|
+
const outStream = this.output;
|
|
437
|
+
const isInput = this.options.isInput;
|
|
438
|
+
return new Promise((resolve, reject) => {
|
|
439
|
+
const rl = readline.createInterface({
|
|
440
|
+
input: fs.createReadStream(tmpFile),
|
|
441
|
+
});
|
|
442
|
+
let errored = false;
|
|
443
|
+
rl.on("line", (line) => {
|
|
444
|
+
const data = extractJSON(line, isInput);
|
|
445
|
+
if (!data) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
onLine(data);
|
|
449
|
+
});
|
|
450
|
+
rl.on("close", () => {
|
|
451
|
+
if (errored) {
|
|
452
|
+
reject(new error_1.FirebaseError("There was an error creating the report."));
|
|
464
453
|
}
|
|
465
454
|
else {
|
|
466
|
-
|
|
455
|
+
const result = onClose();
|
|
456
|
+
if (isFile) {
|
|
457
|
+
outStream.on("finish", () => {
|
|
458
|
+
resolve(result);
|
|
459
|
+
});
|
|
460
|
+
outStream.end();
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
resolve(result);
|
|
464
|
+
}
|
|
467
465
|
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
466
|
+
});
|
|
467
|
+
rl.on("error", () => {
|
|
468
|
+
reject();
|
|
469
|
+
});
|
|
470
|
+
outStream.on("error", () => {
|
|
471
|
+
errored = true;
|
|
472
|
+
rl.close();
|
|
473
|
+
});
|
|
476
474
|
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
this.output.write(data);
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
logger.info(data);
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
ProfileReport.prototype.generate = function () {
|
|
488
|
-
if (this.options.format === "TXT") {
|
|
489
|
-
return this.generateText();
|
|
490
|
-
}
|
|
491
|
-
else if (this.options.format === "RAW") {
|
|
492
|
-
return this.generateRaw();
|
|
493
|
-
}
|
|
494
|
-
else if (this.options.format === "JSON") {
|
|
495
|
-
return this.generateJson();
|
|
496
|
-
}
|
|
497
|
-
throw new FirebaseError('Invalid report format expected "TXT", "JSON", or "RAW"', {
|
|
498
|
-
exit: 1,
|
|
499
|
-
});
|
|
500
|
-
};
|
|
501
|
-
ProfileReport.prototype.generateRaw = function () {
|
|
502
|
-
return this.parse(this.writeRaw.bind(this), function () {
|
|
503
|
-
return null;
|
|
504
|
-
});
|
|
505
|
-
};
|
|
506
|
-
ProfileReport.prototype.writeRaw = function (data) {
|
|
507
|
-
this.write(JSON.stringify(data) + "\n");
|
|
508
|
-
};
|
|
509
|
-
ProfileReport.prototype.generateText = function () {
|
|
510
|
-
return this.parse(this.processOperation.bind(this), this.outputText.bind(this));
|
|
511
|
-
};
|
|
512
|
-
ProfileReport.prototype.outputText = function () {
|
|
513
|
-
var totalTime = this.state.endTime - this.state.startTime;
|
|
514
|
-
var isFile = this.options.isFile;
|
|
515
|
-
var write = this.write.bind(this);
|
|
516
|
-
var writeTitle = function (title) {
|
|
517
|
-
if (isFile) {
|
|
518
|
-
write(title + "\n");
|
|
475
|
+
}
|
|
476
|
+
write(data) {
|
|
477
|
+
if (this.options.isFile) {
|
|
478
|
+
this.output.write(data);
|
|
519
479
|
}
|
|
520
480
|
else {
|
|
521
|
-
|
|
481
|
+
logger_1.logger.info(data);
|
|
522
482
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
writeTitle("Speed Report\n");
|
|
534
|
-
write(SPEED_NOTE + "\n\n");
|
|
535
|
-
writeTable("Read Speed", this.renderReadSpeed());
|
|
536
|
-
writeTable("Write Speed", this.renderWriteSpeed());
|
|
537
|
-
writeTable("Broadcast Speed", this.renderBroadcastSpeed());
|
|
538
|
-
writeTable("Connect Speed", this.renderConnectSpeed());
|
|
539
|
-
writeTable("Disconnect Speed", this.renderDisconnectSpeed());
|
|
540
|
-
writeTable("Unlisten Speed", this.renderUnlistenSpeed());
|
|
541
|
-
writeTitle("Bandwidth Report\n");
|
|
542
|
-
write(BANDWIDTH_NOTE + "\n\n");
|
|
543
|
-
writeTable("Downloaded Bytes", this.renderOutgoingBandwidth());
|
|
544
|
-
writeTable("Uploaded Bytes", this.renderIncomingBandwidth());
|
|
545
|
-
writeTable("Unindexed Queries", this.renderUnindexedData());
|
|
546
|
-
};
|
|
547
|
-
ProfileReport.prototype.generateJson = function () {
|
|
548
|
-
return this.parse(this.processOperation.bind(this), this.outputJson.bind(this));
|
|
549
|
-
};
|
|
550
|
-
ProfileReport.prototype.outputJson = function () {
|
|
551
|
-
var totalTime = this.state.endTime - this.state.startTime;
|
|
552
|
-
var tableToJson = function (table, note) {
|
|
553
|
-
var json = {
|
|
554
|
-
legend: table.options.head,
|
|
555
|
-
data: [],
|
|
556
|
-
};
|
|
557
|
-
if (note) {
|
|
558
|
-
json.note = note;
|
|
483
|
+
}
|
|
484
|
+
generate() {
|
|
485
|
+
if (this.options.format === "TXT") {
|
|
486
|
+
return this.generateText();
|
|
487
|
+
}
|
|
488
|
+
else if (this.options.format === "RAW") {
|
|
489
|
+
return this.generateRaw();
|
|
490
|
+
}
|
|
491
|
+
else if (this.options.format === "JSON") {
|
|
492
|
+
return this.generateJson();
|
|
559
493
|
}
|
|
560
|
-
|
|
561
|
-
|
|
494
|
+
throw new error_1.FirebaseError('Invalid report format expected "TXT", "JSON", or "RAW"');
|
|
495
|
+
}
|
|
496
|
+
generateRaw() {
|
|
497
|
+
return this.parse(this.writeRaw.bind(this), () => {
|
|
498
|
+
return null;
|
|
562
499
|
});
|
|
500
|
+
}
|
|
501
|
+
writeRaw(data) {
|
|
502
|
+
this.write(JSON.stringify(data) + "\n");
|
|
503
|
+
}
|
|
504
|
+
generateText() {
|
|
505
|
+
return this.parse(this.processOperation.bind(this), this.outputText.bind(this));
|
|
506
|
+
}
|
|
507
|
+
outputText() {
|
|
508
|
+
const totalTime = this.state.endTime - this.state.startTime;
|
|
509
|
+
const isFile = this.options.isFile;
|
|
510
|
+
const write = this.write.bind(this);
|
|
511
|
+
const writeTitle = (title) => {
|
|
512
|
+
if (isFile) {
|
|
513
|
+
write(title + "\n");
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
write(clc.bold.yellow(title) + "\n");
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
const writeTable = (title, table) => {
|
|
520
|
+
writeTitle(title);
|
|
521
|
+
write(table.toString() + "\n");
|
|
522
|
+
};
|
|
523
|
+
writeTitle(`Report operations collected from ${new Date(this.state.startTime).toISOString()} over ${totalTime} ms.`);
|
|
524
|
+
writeTitle("Speed Report\n");
|
|
525
|
+
write(SPEED_NOTE + "\n\n");
|
|
526
|
+
writeTable("Read Speed", this.renderReadSpeed());
|
|
527
|
+
writeTable("Write Speed", this.renderWriteSpeed());
|
|
528
|
+
writeTable("Broadcast Speed", this.renderBroadcastSpeed());
|
|
529
|
+
writeTable("Connect Speed", this.renderConnectSpeed());
|
|
530
|
+
writeTable("Disconnect Speed", this.renderDisconnectSpeed());
|
|
531
|
+
writeTable("Unlisten Speed", this.renderUnlistenSpeed());
|
|
532
|
+
writeTitle("Bandwidth Report\n");
|
|
533
|
+
write(BANDWIDTH_NOTE + "\n\n");
|
|
534
|
+
writeTable("Downloaded Bytes", this.renderOutgoingBandwidth());
|
|
535
|
+
writeTable("Uploaded Bytes", this.renderIncomingBandwidth());
|
|
536
|
+
writeTable("Unindexed Queries", this.renderUnindexedData());
|
|
537
|
+
}
|
|
538
|
+
generateJson() {
|
|
539
|
+
return this.parse(this.processOperation.bind(this), this.outputJson.bind(this));
|
|
540
|
+
}
|
|
541
|
+
outputJson() {
|
|
542
|
+
const totalTime = this.state.endTime - this.state.startTime;
|
|
543
|
+
const tableToJson = (table, note) => {
|
|
544
|
+
const json = {
|
|
545
|
+
legend: table.options.head,
|
|
546
|
+
data: [],
|
|
547
|
+
};
|
|
548
|
+
if (note) {
|
|
549
|
+
json.note = note;
|
|
550
|
+
}
|
|
551
|
+
table.forEach((row) => {
|
|
552
|
+
json.data.push(row);
|
|
553
|
+
});
|
|
554
|
+
return json;
|
|
555
|
+
};
|
|
556
|
+
const json = {
|
|
557
|
+
totalTime: totalTime,
|
|
558
|
+
readSpeed: tableToJson(this.renderReadSpeed(), SPEED_NOTE),
|
|
559
|
+
writeSpeed: tableToJson(this.renderWriteSpeed(), SPEED_NOTE),
|
|
560
|
+
broadcastSpeed: tableToJson(this.renderBroadcastSpeed(), SPEED_NOTE),
|
|
561
|
+
connectSpeed: tableToJson(this.renderConnectSpeed(), SPEED_NOTE),
|
|
562
|
+
disconnectSpeed: tableToJson(this.renderDisconnectSpeed(), SPEED_NOTE),
|
|
563
|
+
unlistenSpeed: tableToJson(this.renderUnlistenSpeed(), SPEED_NOTE),
|
|
564
|
+
downloadedBytes: tableToJson(this.renderOutgoingBandwidth(), BANDWIDTH_NOTE),
|
|
565
|
+
uploadedBytes: tableToJson(this.renderIncomingBandwidth(), BANDWIDTH_NOTE),
|
|
566
|
+
unindexedQueries: tableToJson(this.renderUnindexedData()),
|
|
567
|
+
};
|
|
568
|
+
this.write(JSON.stringify(json, null, 2));
|
|
569
|
+
if (this.options.isFile) {
|
|
570
|
+
return this.output.path;
|
|
571
|
+
}
|
|
563
572
|
return json;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
readSpeed: tableToJson(this.renderReadSpeed(), SPEED_NOTE),
|
|
568
|
-
writeSpeed: tableToJson(this.renderWriteSpeed(), SPEED_NOTE),
|
|
569
|
-
broadcastSpeed: tableToJson(this.renderBroadcastSpeed(), SPEED_NOTE),
|
|
570
|
-
connectSpeed: tableToJson(this.renderConnectSpeed(), SPEED_NOTE),
|
|
571
|
-
disconnectSpeed: tableToJson(this.renderDisconnectSpeed(), SPEED_NOTE),
|
|
572
|
-
unlistenSpeed: tableToJson(this.renderUnlistenSpeed(), SPEED_NOTE),
|
|
573
|
-
downloadedBytes: tableToJson(this.renderOutgoingBandwidth(), BANDWIDTH_NOTE),
|
|
574
|
-
uploadedBytes: tableToJson(this.renderIncomingBandwidth(), BANDWIDTH_NOTE),
|
|
575
|
-
unindexedQueries: tableToJson(this.renderUnindexedData()),
|
|
576
|
-
};
|
|
577
|
-
this.write(JSON.stringify(json, null, 2));
|
|
578
|
-
if (this.options.isFile) {
|
|
579
|
-
return this.output.path;
|
|
580
|
-
}
|
|
581
|
-
return json;
|
|
582
|
-
};
|
|
583
|
-
module.exports = ProfileReport;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
exports.ProfileReport = ProfileReport;
|