mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 913260 (part 1) - Simplify TelemetryPing.js a little. r=nfroyd.
--HG-- extra : rebase_source : 0c7e18e269a49ca6dc79623ebc370a6c8440a663
This commit is contained in:
parent
3383f63348
commit
da1fae2328
@ -104,7 +104,7 @@ function generateUUID() {
|
||||
|
||||
/**
|
||||
* Read current process I/O counters.
|
||||
*/
|
||||
*/
|
||||
let processInfo = {
|
||||
_initialized: false,
|
||||
_IO_COUNTERS: null,
|
||||
@ -128,23 +128,23 @@ let processInfo = {
|
||||
{'otherBytes': ctypes.unsigned_long_long} ]);
|
||||
try {
|
||||
this._kernel32 = ctypes.open("Kernel32.dll");
|
||||
this._GetProcessIoCounters = this._kernel32.declare("GetProcessIoCounters",
|
||||
this._GetProcessIoCounters = this._kernel32.declare("GetProcessIoCounters",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.bool, // return
|
||||
ctypes.voidptr_t, // hProcess
|
||||
this._IO_COUNTERS.ptr); // lpIoCounters
|
||||
this._GetCurrentProcess = this._kernel32.declare("GetCurrentProcess",
|
||||
this._GetCurrentProcess = this._kernel32.declare("GetCurrentProcess",
|
||||
ctypes.winapi_abi,
|
||||
ctypes.voidptr_t); // return
|
||||
this._initialized = true;
|
||||
} catch (err) {
|
||||
return null;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
let io = new this._IO_COUNTERS();
|
||||
if(!this._GetProcessIoCounters(this._GetCurrentProcess(), io.address()))
|
||||
return null;
|
||||
return [parseInt(io.readBytes), parseInt(io.writeBytes)];
|
||||
return [parseInt(io.readBytes), parseInt(io.writeBytes)];
|
||||
}
|
||||
};
|
||||
|
||||
@ -172,7 +172,7 @@ TelemetryPing.prototype = {
|
||||
/**
|
||||
* Gets a series of simple measurements (counters). At the moment, this
|
||||
* only returns startup data from nsIAppStartup.getStartupInfo().
|
||||
*
|
||||
*
|
||||
* @return simple measurements as a dictionary.
|
||||
*/
|
||||
getSimpleMeasurements: function getSimpleMeasurements(forSavedSession) {
|
||||
@ -251,12 +251,12 @@ TelemetryPing.prototype = {
|
||||
/**
|
||||
* When reflecting a histogram into JS, Telemetry hands us an object
|
||||
* with the following properties:
|
||||
*
|
||||
*
|
||||
* - min, max, histogram_type, sum, sum_squares_{lo,hi}: simple integers;
|
||||
* - log_sum, log_sum_squares: doubles;
|
||||
* - counts: array of counts for histogram buckets;
|
||||
* - ranges: array of calculated bucket sizes.
|
||||
*
|
||||
*
|
||||
* This format is not straightforward to read and potentially bulky
|
||||
* with lots of zeros in the counts array. Packing histograms makes
|
||||
* raw histograms easier to read and compresses the data a little bit.
|
||||
@ -344,18 +344,9 @@ TelemetryPing.prototype = {
|
||||
return ret;
|
||||
},
|
||||
|
||||
addValue: function addValue(name, id, val) {
|
||||
let h = this._histograms[name];
|
||||
if (!h) {
|
||||
h = Telemetry.getHistogramById(id);
|
||||
this._histograms[name] = h;
|
||||
}
|
||||
h.add(val);
|
||||
},
|
||||
|
||||
/**
|
||||
* Descriptive metadata
|
||||
*
|
||||
*
|
||||
* @param reason
|
||||
* The reason for the telemetry ping, this will be included in the
|
||||
* returned metadata,
|
||||
@ -477,7 +468,7 @@ TelemetryPing.prototype = {
|
||||
|
||||
function h(process, path, kind, units, amount, desc) {
|
||||
if (!hasReported) {
|
||||
boundHandleMemoryReport(id, path, units, amount);
|
||||
boundHandleMemoryReport(id, units, amount);
|
||||
hasReported = true;
|
||||
} else {
|
||||
NS_ASSERT(false,
|
||||
@ -492,7 +483,7 @@ TelemetryPing.prototype = {
|
||||
histogram.add(new Date() - startTime);
|
||||
},
|
||||
|
||||
handleMemoryReport: function(id, path, units, amount) {
|
||||
handleMemoryReport: function(id, units, amount) {
|
||||
let val;
|
||||
if (units == Ci.nsIMemoryReporter.UNITS_BYTES) {
|
||||
val = Math.floor(amount / 1024);
|
||||
@ -508,23 +499,28 @@ TelemetryPing.prototype = {
|
||||
// If the reporter gives us a cumulative count, we'll report the
|
||||
// difference in its value between now and our previous ping.
|
||||
|
||||
if (!(path in this._prevValues)) {
|
||||
if (!(id in this._prevValues)) {
|
||||
// If this is the first time we're reading this reporter, store its
|
||||
// current value but don't report it in the telemetry ping, so we
|
||||
// ignore the effect startup had on the reporter.
|
||||
this._prevValues[path] = amount;
|
||||
this._prevValues[id] = amount;
|
||||
return;
|
||||
}
|
||||
|
||||
val = amount - this._prevValues[path];
|
||||
this._prevValues[path] = amount;
|
||||
val = amount - this._prevValues[id];
|
||||
this._prevValues[id] = amount;
|
||||
}
|
||||
else {
|
||||
NS_ASSERT(false, "Can't handle memory reporter with units " + units);
|
||||
return;
|
||||
}
|
||||
|
||||
this.addValue(path, id, val);
|
||||
let h = this._histograms[id];
|
||||
if (!h) {
|
||||
h = Telemetry.getHistogramById(id);
|
||||
this._histograms[id] = h;
|
||||
}
|
||||
h.add(val);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -534,8 +530,8 @@ TelemetryPing.prototype = {
|
||||
isInterestingStartupHistogram: function isInterestingStartupHistogram(name) {
|
||||
return this._startupHistogramRegex.test(name);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Make a copy of interesting histograms at startup.
|
||||
*/
|
||||
gatherStartupHistograms: function gatherStartupHistograms() {
|
||||
@ -779,7 +775,7 @@ TelemetryPing.prototype = {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
let enabled = false;
|
||||
let enabled = false;
|
||||
try {
|
||||
enabled = Services.prefs.getBoolPref(PREF_ENABLED);
|
||||
this._server = Services.prefs.getCharPref(PREF_SERVER);
|
||||
@ -835,12 +831,12 @@ TelemetryPing.prototype = {
|
||||
getFlashVersion: function getFlashVersion() {
|
||||
let host = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
let tags = host.getPluginTags();
|
||||
|
||||
|
||||
for (let i = 0; i < tags.length; i++) {
|
||||
if (tags[i].name == "Shockwave Flash")
|
||||
return tags[i].version;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
@ -855,7 +851,7 @@ TelemetryPing.prototype = {
|
||||
file, sync, true);
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove observers to avoid leaks
|
||||
*/
|
||||
uninstall: function uninstall() {
|
||||
@ -943,10 +939,10 @@ TelemetryPing.prototype = {
|
||||
break;
|
||||
case "xul-window-visible":
|
||||
Services.obs.removeObserver(this, "xul-window-visible");
|
||||
this._hasXulWindowVisibleObserver = false;
|
||||
this._hasXulWindowVisibleObserver = false;
|
||||
var counters = processInfo.getCounters();
|
||||
if (counters) {
|
||||
[this._startupIO.startupWindowVisibleReadBytes,
|
||||
[this._startupIO.startupWindowVisibleReadBytes,
|
||||
this._startupIO.startupWindowVisibleWriteBytes] = counters;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user