Skip to content

Instantly share code, notes, and snippets.

@new-guy
Created October 15, 2015 17:40
Show Gist options
  • Save new-guy/39af9e5e5ecabf4c1ed7 to your computer and use it in GitHub Desktop.
Save new-guy/39af9e5e5ecabf4c1ed7 to your computer and use it in GitHub Desktop.
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('Profiler'); // -> 'a thing'
*/
var Profiles_open = {}
var Profiles_start = {}
var Profiles_total = {}
function openProfile(profileID){
if(typeof Profiles_open[profileID] === "undefined" ){
Profiles_open[profileID] = 0;
}
if(Profiles_open[profileID] === 0){
Profiles_start[profileID] = Game.getUsedCpu();
}
Profiles_open[profileID] += 1;
}
function closeProfile(profileID){
Profiles_open[profileID]-=1;
if(typeof Profiles_total[profileID] === "undefined"){
Profiles_total[profileID] = 0.0;
}
if(Profiles_open[profileID] === 0){
Profiles_total[profileID] += Game.getUsedCpu()-Profiles_start[profileID];
if(Memory.profiles === undefined) Memory.profiles = {};
Memory.profiles[profileID] = Profiles_total[profileID];
}
}
function showProfiles(){
for(var k in Profiles_total){
console.log(k,Profiles_total[k]);
}
}
exports.getProfiles = function(){
return Profiles_total;
}
module.exports.openProfile = openProfile;
module.exports.closeProfile = closeProfile;
module.exports.showProfiles = showProfiles;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment