Skip to content

Commit

Permalink
disable profiling by default; add URL param to enable it
Browse files Browse the repository at this point in the history
  • Loading branch information
mykmelez committed Sep 22, 2014
1 parent 32746dd commit 91d9692
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<button id="clearstorage">Clear storage</button>
<button id="trace">Trace: OFF</button>
<button id="printAllExceptions">Print all exceptions: OFF</button>
<button id="reportProfile">R</button>
<button id="profile">Profile: OFF</button>
</section>
<section>
<input id="sms_text" type="text" placeholder="SMS text"></input>
Expand Down
54 changes: 35 additions & 19 deletions instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var Instrument = {
enter: {},
exit: {},

profile: {},
profiling: false,
profile: null,

getKey: function(methodInfo) {
return methodInfo.classInfo.className + "." + methodInfo.name + "." + methodInfo.signature;
Expand All @@ -19,28 +20,35 @@ var Instrument = {
Instrument.enter[key](caller, callee);
}

var now = Date.now();
if (this.profiling) {
var now = Date.now();

if (caller.profileData) {
caller.profileData.cost += now - caller.profileData.then;
}
if (caller.profileData) {
caller.profileData.cost += now - caller.profileData.then;
}

callee.profileData = {
cost: 0,
then: now,
};
callee.profileData = {
cost: 0,
then: now,
};
}
},

callExitHooks: function(methodInfo, caller, callee) {
var key = this.getKey(methodInfo);
var now = Date.now();

callee.profileData.cost += now - callee.profileData.then;
var times = this.profile[key] || (this.profile[key] = []);
times.push(callee.profileData.cost);
if (this.profiling) {
var now = Date.now();

if (caller.profileData) {
caller.profileData.then = now;
if (callee.profileData) {
callee.profileData.cost += now - callee.profileData.then;
var times = this.profile[key] || (this.profile[key] = []);
times.push(callee.profileData.cost);
}

if (caller.profileData) {
caller.profileData.then = now;
}
}

if (Instrument.exit[key]) {
Expand All @@ -49,18 +57,23 @@ var Instrument = {
},

callPauseHooks: function(frame) {
if (frame.profileData) {
if (this.profiling && frame.profileData) {
frame.profileData.cost += Date.now() - frame.profileData.then;
}
},

callResumeHooks: function(frame) {
if (frame.profileData) {
if (this.profiling && frame.profileData) {
frame.profileData.then = Date.now();
}
},

reportProfile: function() {
startProfile: function() {
this.profile = {};
this.profiling = true;
},

stopProfile: function() {
var methods = [];

for (var key in this.profile) {
Expand All @@ -74,10 +87,13 @@ var Instrument = {

methods.sort(function(a, b) { return b.time - a.time });

console.log("Profile:");
methods.forEach(function(method) {
console.log(method.time + " " + method.count + " " + method.key);
});
}

this.profiling = false;
},
};

Instrument.enter["com/sun/midp/ssl/SSLStreamConnection.<init>.(Ljava/lang/String;ILjava/io/InputStream;Ljava/io/OutputStream;Lcom/sun/midp/pki/CertStore;)V"] = function(caller, callee) {
Expand Down
1 change: 1 addition & 0 deletions libs/urlparams.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* midletClassName
* network_mcc
* network_mnc
* profile
* pushConn
* pushMidlet
* autosize
Expand Down
21 changes: 18 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ fs.init(function() {
});
});

function getIsOff(button) {
return button.textContent.contains("OFF");
}
function toggle(button) {
var isOff = button.textContent.contains("OFF");
var isOff = getIsOff(button);
button.textContent = button.textContent.replace(isOff ? "OFF" : "ON", isOff ? "ON" : "OFF");
}

Expand All @@ -122,7 +125,19 @@ window.onload = function() {
VM.DEBUG_PRINT_ALL_EXCEPTIONS = !VM.DEBUG_PRINT_ALL_EXCEPTIONS;
toggle(this);
};
document.getElementById("reportProfile").onclick = function() {
Instrument.reportProfile();
document.getElementById("profile").onclick = function() {
if (getIsOff(this)) {
Instrument.startProfile();
} else {
Instrument.stopProfile();
}
toggle(this);
};
if (Instrument.profiling) {
toggle(document.getElementById("profile"));
}
};

if (urlParams.profile && !/no|0/.test(urlParams.profile)) {
Instrument.startProfile();
}

0 comments on commit 91d9692

Please sign in to comment.