Skip to content

Commit c69b9b0

Browse files
author
Harald Kirschner
committed
v0.0.1
0 parents  commit c69b9b0

19 files changed

+3893
-0
lines changed

.eslintignore

Whitespace-only changes.

.eslintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"globals": {
3+
"browser": true,
4+
"chrome": true,
5+
},
6+
"rules": {
7+
"no-set-state": "off",
8+
"no-console": "off",
9+
"no-unused-vars": "off",
10+
"no-case-declarations": "off"
11+
},
12+
"env": {
13+
"browser": true,
14+
"es6": true,
15+
"node": true
16+
},
17+
"parserOptions": {
18+
"ecmaVersion": 2017
19+
},
20+
"extends": [
21+
"eslint:recommended"
22+
]
23+
}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.xpi
2+
.profile
3+
node_modules
4+
**/*-bundle.js
5+
.env

LICENSE

Lines changed: 362 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Personal Performance Beacon: Addon
2+
3+
Crowd-sourced Firefox profiling.
4+
5+
See [Server](https://github.com/digitarald/ppb-server).
6+
7+
## Attribution
8+
9+
[Stopwatch](https://www.iconfinder.com/icons/353443/clock_stopwatch_timer_watch_icon) is part of the [Glypho Icon Pack](http://glypho.eu/) by [Cristian Bogdan Rosu](http://www.bogdanrosu.com/)

addon/lib/profiler-port.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const profiler = require('./profiler');
2+
3+
module.exports = (port) => {
4+
port.onMessage.addListener(async function(msg) {
5+
switch (msg.name) {
6+
case 'start':
7+
profiler.start(msg.settings);
8+
port.postMessage({ name: 'start' });
9+
break;
10+
case 'stop':
11+
profiler.stop();
12+
port.postMessage({ name: 'stop' });
13+
break;
14+
case 'getData':
15+
const data = await profiler.getData();
16+
console.log(`getData yielded ${JSON.stringify(data).length} bytes`);
17+
port.postMessage({
18+
name: 'getData',
19+
data: data
20+
});
21+
break;
22+
case 'getStatus':
23+
port.postMessage({
24+
name: 'getStatus',
25+
data: profiler.isActive() || false
26+
});
27+
break;
28+
}
29+
});
30+
};

addon/lib/profiler.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { Cc, Ci } = require("chrome");
2+
3+
class Profiler {
4+
constructor() {
5+
this.service = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
6+
}
7+
8+
start({entries = 10000000, interval = 1, features = ['stackwalk'], threads = []}) {
9+
this.service.StartProfiler(entries, interval, features, features.length, threads, threads.length);
10+
}
11+
12+
stop() {
13+
this.service.StopProfiler();
14+
}
15+
16+
getData() {
17+
return this.service.getProfileDataAsync();
18+
}
19+
20+
isActive() {
21+
return this.service.IsActive();
22+
}
23+
}
24+
25+
module.exports = new Profiler();

addon/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const webext = require("sdk/webextension");
2+
const connectProfiler = require("./lib/profiler-port");
3+
4+
webext.startup().then(({browser}) => {
5+
browser.runtime.onConnect.addListener(connectProfiler);
6+
});

addon/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title": "Personal Performance Beacon",
3+
"name": "personal-performance-beacon",
4+
"description": "Crowd-sourced Firefox Profiling.",
5+
"author": "Quantum Flow <quantum-flow@mozilla.org>",
6+
"version": "0.0.2",
7+
"main": "./main.js",
8+
"engines": {
9+
"firefox": ">=53.0"
10+
},
11+
"permissions": {
12+
"multiprocess": true
13+
},
14+
"hasEmbeddedWebExtension": true,
15+
"license": "MPL",
16+
"preferences": [
17+
{
18+
"name": "reportUrl",
19+
"title": "Reporter URL",
20+
"description": "Collected profiles get posted to this URL",
21+
"type": "string",
22+
"value": "https://profile-analyzer.firebaseapp.com/"
23+
}
24+
]
25+
}
Lines changed: 18 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Loading

addon/webextension/manifest.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "SDK Transition Addon",
3+
"version": "0.0.1",
4+
"manifest_version": 2,
5+
"permissions": [
6+
"webNavigation",
7+
"storage",
8+
"https://quantum-ppb.herokuapp.com/",
9+
"https://quantum-flow.s3.amazonaws.com/",
10+
"https://www.google-analytics.com/"
11+
],
12+
"background": {
13+
"scripts": ["background.js"]
14+
},
15+
"browser_action": {
16+
"default_icon": "icons/icon-default.svg",
17+
"default_title": "Personal Performance Beacon",
18+
"browser_style": false
19+
}
20+
}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title": "Personal Performance Beacon Addon",
3+
"name": "ppb-addon",
4+
"description": "Crowd-sourced Firefox Profiling.",
5+
"author": "Quantum Flow <quantum-flow@mozilla.org>",
6+
"version": "0.0.1",
7+
"scripts": {
8+
"test:lint": "eslint **/*.js",
9+
"bundle:dev": "webpack",
10+
"bundle:prod": "NODE_ENV=production webpack",
11+
"start": "npm run bundle:dev && npm run start:browser",
12+
"sign": "jpm sign --addon-dir addon --api-key $JWT_ISSUER --api-secret $JWT_SECRET",
13+
"start:browser": "jpm run --addon-dir addon --binary /Applications/FirefoxNightly.app --profile ./.profile --no-copy",
14+
"start:post": "npm run bundle:dev && jpm post --addon-dir addon --post-url http://127.0.0.1:8888",
15+
"build": "npm run bundle:prod && npm run sign"
16+
},
17+
"devDependencies": {
18+
"eslint": "^3.18.0",
19+
"jpm": "^1.3.0",
20+
"webpack": "^2.2.1"
21+
},
22+
"dependencies": {
23+
"pako": "^1.0.4"
24+
}
25+
}

webextension/analytics.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const stringifyQuery = (params) => {
2+
var esc = encodeURIComponent;
3+
return Object.keys(params)
4+
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
5+
.join('&');
6+
}
7+
8+
module.exports = class Analytics {
9+
10+
constructor(tid) {
11+
this.tid = tid;
12+
this.cid = '0';
13+
}
14+
15+
setClient(cid) {
16+
this.cid = cid;
17+
}
18+
19+
track(type, params) {
20+
Object.assign(params, {
21+
v: 1,
22+
tid: this.tid,
23+
cid: this.cid,
24+
aip: 1,
25+
ds: 'addon',
26+
t: type
27+
});
28+
// console.log(`analytics track: ${type}`, params);
29+
fetch('https://www.google-analytics.com/collect', {
30+
method: 'post',
31+
body: stringifyQuery(params)
32+
});
33+
}
34+
35+
trackEvent(category, action, label = '', value = '') {
36+
this.track('event', {
37+
ec: category,
38+
ea: action,
39+
el: label,
40+
ev: value
41+
});
42+
}
43+
44+
trackException(description, fatal = false) {
45+
this.track('exception', {
46+
exd: description,
47+
exf: fatal ? 1 : 0
48+
});
49+
}
50+
51+
trackUserTiming(category, variable, time = 0) {
52+
this.track('timing', {
53+
utc: category,
54+
utv: variable,
55+
utt: time
56+
});
57+
}
58+
}

0 commit comments

Comments
 (0)