import numpy
import ujson as json
import matplotlib.pyplot as plt
import pandas as pd
import random
import re
import IPython
import time
from moztelemetry.spark import get_pings
from moztelemetry.histogram import Histogram
IPython.core.pylabtools.figsize(18, 7)
sc.defaultParallelism
64
Number of pings considered:
%%capture
pings = get_pings(sc, "Firefox", "nightly", "*", "*", ("20150101", "20150109"))
pings.count()
1337946
%%capture
name_version_regexp = re.compile("^([-a-zA-Z\s\d]*[a-zA-Z])([\d.]*)$")
def extract_name_version(raw):
m = re.match(name_version_regexp, raw)
if not m: # missing plugin name
return [None, None]
else:
return m.groups()
def parse(ping):
return json.loads(ping)
def get_keyed_histograms(name, container, os, async):
histograms = container.get(name, None)
if not histograms:
return []
res = []
for k, v in histograms.iteritems():
plugin_name, version = extract_name_version(k)
res.append([name, os, async, plugin_name, version, Histogram(name, v).get_values()])
return res
def extract(ping):
output = []
os = ping["info"].get("OS")
keyed = ping.get("keyedHistograms", None)
if not os or not keyed:
return output
async_surrogate = keyed.get("BLOCKED_ON_PLUGINASYNCSURROGATE_WAITFORINIT_MS", None)
if async_surrogate is not None and len(async_surrogate) == 0: # Ignore existing but empty histogram
return output
async = bool(async_surrogate)
output += get_keyed_histograms("BLOCKED_ON_PLUGIN_MODULE_INIT_MS", keyed, os, async)
output += get_keyed_histograms("BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS", keyed, os, async)
output += get_keyed_histograms("BLOCKED_ON_PLUGIN_STREAM_INIT_MS", keyed, os, async)
output += get_keyed_histograms("BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS", keyed, os, async)
return output
data = pings.map(parse).flatMap(extract)
Total number of histograms collected:
%%capture
collected_data = data.collect()
len(collected_data)
236096
%%capture
frame = pd.DataFrame(data.collect(), columns=["histogram", "os", "async", "plugin", "version", "values"])
top_plugins = frame["plugin"].value_counts()[:5].index
top_frame = frame[frame["plugin"].isin(top_plugins)]
top_frame["ping"] = 1
top_frame.to_json("1118762.json")
#top_frame = pd.read_json("1118762.json")
Split, apply, combine groups:
grouped = top_frame.groupby(["plugin", "os", "histogram", "async"])
aggregates = grouped[["values", "ping"]].apply(lambda x: pd.Series({"values": x["values"].sum().values, "pings": x["ping"].sum()}))
def plot(data):
for plugin in top_plugins: # Sorted by popularity
plot_os(plugin, data.ix[plugin])
def plot_os(plugin, data):
for os in ["WINNT", "Darwin", "Linux"]:
plot_histograms(plugin, os, data.ix[os])
def plot_histograms(plugin, os, data):
print "Operating System: " + os # Useful for grepping
print "Plugin: " + plugin
fig = plt.figure(figsize=(30, 5))
fig.subplots_adjust(hspace=0.3)
for idx, histogram in enumerate(data.index.levels[0]):
ax = fig.add_subplot(1, 4, idx + 1)
plot_comparison(plugin, os, histogram, ax, data.ix[histogram])
plt.show()
def plot_comparison(plugin, os, histogram, ax, data):
hsync = Histogram(histogram, data.ix[False]["values"]) if False in data.index else None
hasync = Histogram(histogram, data.ix[True]["values"]) if True in data.index else None
ax2 = ax.twinx()
width = 0.4
if hasync is not None:
print "async {} ({} submissions): Q1 {:.2f} - Q2 {:.2f} - Q3 {:.2f}".format(histogram, data.ix[True]["pings"],
hasync.percentile(25), hasync.percentile(50), hasync.percentile(75))
async = hasync.get_values()
async = async/async.sum()
async.plot(kind="bar", color="green", ax=ax, width=width, position=0, label="async")
if hsync is not None:
print "sync {} ({} submissions): Q1 {:.2f} - Q2 {:.2f} - Q3 {:.2f}\n".format(histogram, data.ix[False]["pings"],
hsync.percentile(25), hsync.percentile(50), hsync.percentile(75))
sync = hsync.get_values()
sync = sync/sync.sum()
sync.plot(kind="bar", color="blue", ax=ax2, width=width, position=1, grid=False, label="sync", ylim=ax.get_ylim())
plt.title("{} - {} - {}".format(os, plugin, histogram))
plt.ylabel("Normalized count")
if hasync and hsync:
ax.legend(ax.get_legend_handles_labels()[0] + ax2.get_legend_handles_labels()[0], ["async", "sync"])
elif hasync:
ax.legend(ax.get_legend_handles_labels()[0], ["async"])
else:
ax.legend(ax2.get_legend_handles_labels()[0], ["sync"])
plot(aggregates)
Operating System: WINNT Plugin: Shockwave Flash async BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (227 submissions): Q1 0.88 - Q2 44.55 - Q3 63.71 sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (49525 submissions): Q1 38.15 - Q2 57.25 - Q3 112.85 async BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (228 submissions): Q1 0.25 - Q2 0.51 - Q3 0.76 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (49678 submissions): Q1 6.31 - Q2 12.15 - Q3 21.87 async BLOCKED_ON_PLUGIN_MODULE_INIT_MS (228 submissions): Q1 0.54 - Q2 1.15 - Q3 2.47 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (47853 submissions): Q1 53.19 - Q2 132.26 - Q3 409.47 async BLOCKED_ON_PLUGIN_STREAM_INIT_MS (206 submissions): Q1 0.25 - Q2 0.50 - Q3 0.76 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (46280 submissions): Q1 0.67 - Q2 1.59 - Q3 5.89
Operating System: Darwin Plugin: Shockwave Flash async BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (5 submissions): Q1 86.53 - Q2 131.90 - Q3 225.84 sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (772 submissions): Q1 43.12 - Q2 60.55 - Q3 113.14 async BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (5 submissions): Q1 0.25 - Q2 0.50 - Q3 0.75 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (772 submissions): Q1 5.42 - Q2 8.89 - Q3 21.24 async BLOCKED_ON_PLUGIN_MODULE_INIT_MS (5 submissions): Q1 0.46 - Q2 0.92 - Q3 1.75 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (756 submissions): Q1 65.19 - Q2 94.41 - Q3 168.93 async BLOCKED_ON_PLUGIN_STREAM_INIT_MS (5 submissions): Q1 0.25 - Q2 0.50 - Q3 0.75 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (722 submissions): Q1 0.60 - Q2 1.30 - Q3 2.86
Operating System: Linux Plugin: Shockwave Flash async BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (25 submissions): Q1 27.12 - Q2 86.02 - Q3 139.49 sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (922 submissions): Q1 22.66 - Q2 33.15 - Q3 104.45 async BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (25 submissions): Q1 0.26 - Q2 0.52 - Q3 0.78 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (922 submissions): Q1 2.43 - Q2 5.83 - Q3 14.78 async BLOCKED_ON_PLUGIN_MODULE_INIT_MS (25 submissions): Q1 0.30 - Q2 0.60 - Q3 0.89 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (843 submissions): Q1 51.92 - Q2 81.28 - Q3 155.65 async BLOCKED_ON_PLUGIN_STREAM_INIT_MS (23 submissions): Q1 0.25 - Q2 0.50 - Q3 0.75 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (854 submissions): Q1 0.55 - Q2 1.17 - Q3 2.22
Operating System: WINNT Plugin: Plugins PDK sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (1867 submissions): Q1 2.02 - Q2 4.96 - Q3 12.37 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (1913 submissions): Q1 0.60 - Q2 6.83 - Q3 17.39 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (1863 submissions): Q1 139.25 - Q2 244.97 - Q3 453.36
Operating System: Darwin Plugin: Plugins PDK
Operating System: Linux Plugin: Plugins PDK
Operating System: WINNT Plugin: Unity Player sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (936 submissions): Q1 2.78 - Q2 4.94 - Q3 189.69 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (937 submissions): Q1 8.20 - Q2 17.83 - Q3 34.87 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (911 submissions): Q1 66.71 - Q2 166.61 - Q3 500.17 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (238 submissions): Q1 0.80 - Q2 1.89 - Q3 7.56
Operating System: Darwin Plugin: Unity Player
Operating System: Linux Plugin: Unity Player
Operating System: WINNT Plugin: Silverlight Plug-In sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (667 submissions): Q1 46.85 - Q2 133.78 - Q3 261.78 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (680 submissions): Q1 36.52 - Q2 91.33 - Q3 247.54 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (658 submissions): Q1 48.06 - Q2 105.67 - Q3 366.99 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (680 submissions): Q1 0.43 - Q2 0.86 - Q3 1.70
Operating System: Darwin Plugin: Silverlight Plug-In sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (22 submissions): Q1 9.90 - Q2 76.64 - Q3 196.79 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (22 submissions): Q1 18.17 - Q2 34.27 - Q3 78.40 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (22 submissions): Q1 155.89 - Q2 257.92 - Q3 456.33 sync BLOCKED_ON_PLUGIN_STREAM_INIT_MS (22 submissions): Q1 0.49 - Q2 0.98 - Q3 6.51
Operating System: Linux Plugin: Silverlight Plug-In
Operating System: WINNT Plugin: Virtual Keyboard KAV async BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (2 submissions): Q1 0.50 - Q2 1.00 - Q3 3.00 sync BLOCKED_ON_PLUGIN_INSTANCE_DESTROY_MS (514 submissions): Q1 2.05 - Q2 5.47 - Q3 10.80 async BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (2 submissions): Q1 0.25 - Q2 0.50 - Q3 0.75 sync BLOCKED_ON_PLUGIN_INSTANCE_INIT_MS (535 submissions): Q1 0.69 - Q2 9.02 - Q3 19.75 async BLOCKED_ON_PLUGIN_MODULE_INIT_MS (2 submissions): Q1 29.50 - Q2 37.00 - Q3 82.50 sync BLOCKED_ON_PLUGIN_MODULE_INIT_MS (476 submissions): Q1 119.52 - Q2 231.17 - Q3 432.83
Operating System: Darwin Plugin: Virtual Keyboard KAV
Operating System: Linux Plugin: Virtual Keyboard KAV