forked from qualialabs/profile
/
method.js
29 lines (26 loc) · 861 Bytes
/
method.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Meteor } from 'meteor/meteor';
import Profiler from './main';
import { uploadFileToS3Sync } from './s3';
const PACKAGE_NAME = 'quave:profile';
Meteor.methods({
'quave:profile#execute': ({ durationMs = 1000, name, folder = '' } = {}) => {
const now = new Date();
const profileName =
name ||
`profile-${now.getFullYear()}-${now.getMonth() +
1}-${now.getDate()}-${now.getTime()}`;
console.log(`profileName`, profileName);
Profiler.profileDuration(
profileName,
`${profileName}.cpuprofile`,
durationMs,
Meteor.bindEnvironment((exportPath, result) => {
const uploaded = uploadFileToS3Sync(
result,
`${folder}${folder && !folder.endsWith('/') ? '/' : ''}${exportPath}`
);
console.log(`[${PACKAGE_NAME}] URL`, uploaded.url);
})
);
},
});