Permalink
Browse files

Make property names and type customizable and thus remove hard coding…

… from timeline.jsm
  • Loading branch information...
1 parent 8c9df22 commit b5ffbf9fc36fa2864454aa8dc35ba76810443f15 @grssam committed Jul 8, 2012
Binary file not shown.
@@ -212,14 +212,13 @@ TimelineView.prototype = {
if (!producerBox) {
return;
}
- let request = aData.details.log.entries[0].request;
let featureBox = producerBox.firstChild.nextSibling;
let urlLabel = this._frameDoc.createElement("label");
urlLabel.setAttribute("id", aData.groupID.replace(" ", "_") + "-groupbox");
urlLabel.setAttribute("class", "timeline-groubox");
urlLabel.setAttribute("groupId", aData.groupID);
urlLabel.setAttribute("shouldDelete", true);
- urlLabel.setAttribute("value", request.method.toUpperCase() + " " + request.url);
+ urlLabel.setAttribute("value", aData.name);
urlLabel.setAttribute("flex", "0");
urlLabel.setAttribute("crop", "center");
featureBox.appendChild(urlLabel);
@@ -707,59 +706,40 @@ TimelineView.prototype = {
}
feedItem.setAttribute("groupId", aData.groupID);
feedItem.setAttribute("timestamp", aData.time);
- // The only hard coded part of the code.
let label1 = this._frameDoc.createElement("label");
label1.setAttribute("style", "color:" + COLOR_LIST[aId%12]);
let label2 = this._frameDoc.createElement("label");
label2.setAttribute("style", "color:" + COLOR_LIST[aId%12]);
let dateString = (new Date(aData.time)).getHours() + ":" +
(new Date(aData.time)).getMinutes() + ":" +
(new Date(aData.time)).getSeconds();
- switch (aData.producer) {
- case "NetworkProducer":
- let request = aData.details.log.entries[0].request;
- label1.setAttribute("value", request.method.toUpperCase() + " " + request.url);
- feedItem.appendChild(label1);
- label2.setAttribute("value", aData.name + " at " + dateString);
- feedItem.appendChild(label2);
- break;
-
- case "PageEventsProducer":
- if (aData.groupID == "MouseEvent") {
- label1.setAttribute("value", aData.name + " at (" +
- aData.details.detail.screenX + "," +
- aData.details.detail.screenY + ")");
- }
- else if (aData.groupID == "KeyboardEvent") {
- label1.setAttribute("value", aData.name + ", Key " +
- String.fromCharCode(aData.details.detail.charCode));
- }
- else {
- label1.setAttribute("value", aData.name + " at " + dateString)
- }
- feedItem.appendChild(label1);
- if (aData.groupID == "MouseEvent") {
- label2.setAttribute("value", "on Id " + aData.details.target + " at " + dateString);
- feedItem.appendChild(label2);
- }
- else if (aData.groupID == "KeyboardEvent") {
- label2.setAttribute("value", "on Id " + aData.details.target + " at " + dateString);
+ label1.setAttribute("value", aData.name);
+ feedItem.appendChild(label1);
+ if (aData.details) {
+ for (let property in aData.details) {
+ if (Timeline.producerInfoList[aData.producer]
+ .details[property].type != "nested") {
+ let {name:name, value:value} =
+ this.getPropertyInfo(aData.producer,
+ property,
+ aData.details[property]);
+ label2.setAttribute("value", name + ": " + value + " at " + dateString);
feedItem.appendChild(label2);
}
- break;
-
- case "MemoryProducer":
- label1.setAttribute("value", aData.name + " at " + dateString);
- feedItem.appendChild(label1);
- if (aData.name == "Garbage Collection") {
- label2.setAttribute("value", "Total Slices: " + aData.details.total_slices +
- ", Total Time: " + aData.details.total_time + "ms");
- feedItem.appendChild(label2);
+ else {
+ for (let subProp in aData.details[property].items) {
+ let {name:name, value:value} =
+ this.getPropertyInfo(aData.producer,
+ property,
+ aData.details[property].items[subProp],
+ subProp);
+ label2.setAttribute("value", name + ": " + value + " at " + dateString);
+ feedItem.appendChild(label2);
+ break;
+ }
}
break;
-
- default:
- return;
+ }
}
this.tickerGroups.push(aData.groupID);
if (!this.infoBox.firstChild) {
@@ -774,6 +754,63 @@ TimelineView.prototype = {
},
/**
+ * Returns display name and value corresponding to a property.
+ *
+ * @param string aProducerId
+ * producer ID corresponding to the property.
+ * @param string aName
+ * Name of the property.
+ * @param * aValue
+ * Value of the property.
+ * @param string aSubName
+ * sub property name in case of nested type.
+ * @return {name: _name_, value: _value_}
+ * _name_ is the display name, _value_ is the display value.
+ */
+ getPropertyInfo: function TV_getPropertyInfo(aProducerId, aName, aValue, aSubName)
+ {
+ if (Timeline.producerInfoList[aProducerId].details[aName]) {
+ let details = Timeline.producerInfoList[aProducerId].details;
+ let type = details[aName].type;
+ let name,value;
+ if (type == "nested") {
+ if (aSubName != null) {
+ type = details[aName].items[aSubName].type;
+ details = details[aName].items;
+ aName = aSubName;
+ }
+ else {
+ return null;
+ }
+ }
+ switch (type) {
+ case "string":
+ case "number":
+ value = aValue;
+ name = details[aName].name;
+ break;
+
+ case "date":
+ value = (new Date(aValue)).getHours() + ":" +
+ (new Date(aValue)).getMinutes() + ":" +
+ (new Date(aValue)).getSeconds();
+ name = details[aName].name;
+ break;
+
+ case "enum":
+ name = details[aName].name;
+ value = details[aName].values[aValue] || "null";
+ break;
+
+ default:
+ return null;
+ }
+ return {name: name, value: value};
+ }
+ return null;
+ },
+
+ /**
* Gets the data and sends it to the canvas to display
*
* @param object aData
@@ -158,8 +158,8 @@ let MemoryProducer =
let slices = data['slices'];
startingTime -= (slices[slices.length - 1].when + slices[slices.length - 1].pause);
data = {
- timestamp: startingTime,
total_slices: slices.length,
+ timestamp: startingTime,
total_time: data['total_time'],
compartments_collected: data['compartments_collected'],
total_compartments: data['total_compartments'],
@@ -174,6 +174,7 @@ let MemoryProducer =
for (let i = 0; i < slices.length; i++) {
data['duration'] = slices[i].pause;
data['timestamp'] = startingTime + slices[i].when;
+ data.slice_no = i;
// Send 2 notification for each slice
DataSink.addEvent("MemoryProducer", {
type: DataSink.NormalizedEventType.REPEATING_EVENT_START,
@@ -221,6 +222,24 @@ let producerInfo = {
// Features of this producer that can be turned on or off.
// For this producer, its the list of observedEvents
features: ["Cycle Collection", "Garbage Collection"/*, "Memory Statistics"*/],
+ // detail view will show properties belonging represented by these names.
+ // "propertyName": {name: "display name", type: "boolean", values:{true: "Yes", false: "No"}]
+ details: {
+ timestamp: {name: "Time", type: "date"},
+ duration: {name: "Duration", type: "number"},
+ slice_no: {name: "Slice Number", type: "number"},
+ total_slices: {name: "Total Slices", type: "number"},
+ total_time: {name: "Total Time", type: "number"},
+ compartments_collected: {name: "Compartments Collected", type: "number"},
+ total_compartments: {name: "Total Compartments", type: "number"},
+ mmu_20ms: {name: "20ms MMU", type: "number"},
+ mmu_50ms: {name: "50 ms MMU", type: "number"},
+ max_pause: {name: "Max. Pause", type: "number"},
+ nonincremental_reason: {name: "Non Incremental Reason", type: "string"},
+ allocated: {name: "Allocated", type: "string"},
+ added_chunks: {name: "Chunks Added", type: "number"},
+ removed_chunks: {name: "Chunks Removed", type: "number"},
+ }
};
// Register this producer to Data Sink
Oops, something went wrong.

0 comments on commit b5ffbf9

Please sign in to comment.