Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments for Meteor 3 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages
.idea
.envrc
49 changes: 27 additions & 22 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Meteor.methods({
"monti.profileCpu": profileMethodHandler,
});

function profileMethodHandler (arg1, arg2, type) {
async function profileMethodHandler (arg1, arg2, type) {
check(arguments, [Match.Any]);

this.unblock();

if (type === 'remote') {
Expand Down Expand Up @@ -53,7 +54,7 @@ remoteProfileCPU = function(timeToProfileSecs, id) {
}
};

localProfileCPU = function(timeToProfileSecs, outputLocation) {
localProfileCPU = async function(timeToProfileSecs, outputLocation) {
if(!process.env.KADIRA_PROFILE_LOCALLY && !process.env.MONTI_PROFILE_LOCALLY) {
throw new Meteor.Error(403, "run your app with `MONTI_PROFILE_LOCALLY` env variable to profile locally.")
}
Expand All @@ -63,42 +64,46 @@ localProfileCPU = function(timeToProfileSecs, outputLocation) {
outputLocation = path.resolve(os.tmpdir(), name + '.cpuprofile');
}
console.log('Monti APM: Started CPU profiling for %s secs.', timeToProfileSecs);
var profile = getCpuProfile(name, timeToProfileSecs);
var profile = await getCpuProfile(name, timeToProfileSecs);

console.log('Monti APM: Saving CPU profile to: ' + outputLocation);
writeToDisk(outputLocation, profile);
await fs.promises.writeFile(outputLocation, profile);
console.log('Monti APM: CPU profile saved.');

return "Cpu profile has been saved to: " + outputLocation;
};

getCpuProfile = Kadira._wrapAsync(function(name, timeToProfileSecs, callback) {
var v8Profiler = binaryRequire('v8-profiler-next');
v8Profiler.startProfiling(name);
setTimeout(function() {
var profile = v8Profiler.stopProfiling(name);
profile.export((err, result) => {
if (err) {
callback(err);
}

profile.delete();
callback(null, result);
});
}, timeToProfileSecs * 1000);
});
getCpuProfile = function(name, timeToProfileSecs) {
return new Promise((resolve, reject) => {
var v8Profiler = binaryRequire('v8-profiler-next');
v8Profiler.startProfiling(name);
setTimeout(function() {
var profile = v8Profiler.stopProfiling(name);
profile.export((err, result) => {
if (err) {
reject(err);
return
}

profile.delete();
resolve(result);
});
}, timeToProfileSecs * 1000);
})
};

writeToDisk = Kadira._wrapAsync(fs.writeFile);
writeToDisk = fs.promises.writeFile

function uploadProfile (profile, url) {
async function uploadProfile (profile, url) {
console.trace();
return Kadira.coreApi._send(url, {
data: profile,
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(profile)
},
method: 'PUT',
}).await();
})
}

function binaryRequire(moduleName) {
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Package.onTest(function(api) {
});

function configurePackage(api) {
api.versionsFrom('METEOR@1.4');
api.versionsFrom('METEOR@3.0-alpha.17');
api.use('check');
api.use('random');
api.export('MontiProfiler');
api.use('montiapm:agent@2.44.2');
api.imply('montiapm:agent@2.44.2');
api.use('montiapm:agent');
api.imply('montiapm:agent');
api.use('montiapm:[email protected]');

api.addFiles('lib/server.js', 'server');
Expand Down
Loading