add basic debugger analytics

This commit is contained in:
Dave Holoway
2020-07-03 00:15:39 +01:00
parent cc3b995de3
commit 33daf68649
3 changed files with 48 additions and 7 deletions

View File

@@ -8,10 +8,11 @@ const timeLabels = new Map();
let session_start = Date.now(); let session_start = Date.now();
/** /**
* @param {string} t * @param {string} [t]
* @param {string} u * @param {string} [u]
* @param {string} s * @param {string} [s]
* @param {{name:string,version:string}} package_json * @param {{name:string,version:string}} [package_json]
* @param {*} [props]
*/ */
function init(t = '0cca95950055c6553804a46ce7e3df18', u, s, package_json, props) { function init(t = '0cca95950055c6553804a46ce7e3df18', u, s, package_json, props) {
if (mp) { if (mp) {
@@ -20,10 +21,15 @@ function init(t = '0cca95950055c6553804a46ce7e3df18', u, s, package_json, props)
try { try {
mp = require('mixpanel').init(t); mp = require('mixpanel').init(t);
} }
catch {} catch {
return;
}
uid = u; uid = u;
sid = s; sid = s;
if (!props) {
return;
}
const os = require('os'); const os = require('os');
event(`${package_json.name}-start`, { event(`${package_json.name}-start`, {
extension: package_json.name, extension: package_json.name,
@@ -56,7 +62,7 @@ function event(eventName, properties) {
...properties, ...properties,
}); });
} else { } else {
mp.track(eventName); mp.track(eventName, properties);
} }
} catch {} } catch {}
} }

View File

@@ -17,6 +17,11 @@ class APKFileInfo {
*/ */
file_data = null; file_data = null;
/**
* The size of the APK file (in bytes)
*/
file_size = 0;
/** /**
* last modified time of the APK file (in ms) * last modified time of the APK file (in ms)
*/ */
@@ -67,6 +72,7 @@ class APKFileInfo {
// read the APK file contents // read the APK file contents
try { try {
result.file_data = await readFile(args.apkFile); result.file_data = await readFile(args.apkFile);
result.file_size = result.file_data.length;
} catch(err) { } catch(err) {
throw new Error(`APK read error. ${err.message}`); throw new Error(`APK read error. ${err.message}`);
} }

View File

@@ -6,6 +6,7 @@ const {
// node and external modules // node and external modules
const os = require('os'); const os = require('os');
const path = require('path'); const path = require('path');
const uuidv4 = require('uuid').v4;
// our stuff // our stuff
const { ADBClient } = require('./adbclient'); const { ADBClient } = require('./adbclient');
@@ -20,6 +21,7 @@ const { checkADBStarted, getAndroidSourcesFolder } = require('./utils/android');
const { D, initLogToClient, onMessagePrint } = require('./utils/print'); const { D, initLogToClient, onMessagePrint } = require('./utils/print');
const { hasValidSourceFileExtension } = require('./utils/source-file'); const { hasValidSourceFileExtension } = require('./utils/source-file');
const { VariableManager } = require('./variable-manager'); const { VariableManager } = require('./variable-manager');
const analytics = require('../langserver/analytics');
class AndroidDebugSession extends DebugSession { class AndroidDebugSession extends DebugSession {
@@ -107,6 +109,10 @@ class AndroidDebugSession extends DebugSession {
*/ */
this.debug_mode = null; this.debug_mode = null;
this.session_id = uuidv4();
this.session_start = new Date();
analytics.init();
// this debugger uses one-based lines and columns // this debugger uses one-based lines and columns
this.setDebuggerLinesStartAt1(true); this.setDebuggerLinesStartAt1(true);
this.setDebuggerColumnsStartAt1(true); this.setDebuggerColumnsStartAt1(true);
@@ -417,6 +423,14 @@ class AndroidDebugSession extends DebugSession {
this.LOG(`Debugger attached`); this.LOG(`Debugger attached`);
await this.dbgr.resume(); await this.dbgr.resume();
analytics.event('debug-started', {
dbg_session_id: this.session_id,
dbg_start: this.session_start.toLocaleTimeString(),
dbg_tz: this.session_start.getTimezoneOffset(),
dbg_kind: 'attach',
dbg_device_api: this.device_api_level,
dbg_emulator: /^emulator/.test(this._device.serial),
})
} catch(e) { } catch(e) {
//this.performDisconnect(); //this.performDisconnect();
// exceptions use message, adbclient uses msg // exceptions use message, adbclient uses msg
@@ -558,6 +572,17 @@ class AndroidDebugSession extends DebugSession {
this.sendResponse(response); this.sendResponse(response);
await this.dbgr.resume(); await this.dbgr.resume();
analytics.event('debug-started', {
dbg_session_id: this.session_id,
dbg_start: this.session_start.toLocaleTimeString(),
dbg_tz: this.session_start.getTimezoneOffset(),
dbg_kind: 'debug',
dbg_device_api: this.device_api_level,
dbg_emulator: /^emulator/.test(this._device.serial),
dbg_apk_size: this.apk_file_info.file_size,
dbg_pkg_name: this.apk_file_info.manifest.package || '',
})
this.LOG('Application started'); this.LOG('Application started');
} catch(e) { } catch(e) {
// exceptions use message, adbclient uses msg // exceptions use message, adbclient uses msg
@@ -748,6 +773,10 @@ class AndroidDebugSession extends DebugSession {
async disconnectRequest(response) { async disconnectRequest(response) {
D('disconnectRequest'); D('disconnectRequest');
this._isDisconnecting = true; this._isDisconnecting = true;
analytics.event('debug-end', {
dbg_session_id: this.session_id,
dbg_elapsed: Math.trunc((Date.now() - this.session_start.getTime())/1e3),
});
if (this.debuggerAttached) { if (this.debuggerAttached) {
try { try {
if (this.debug_mode === 'launch') { if (this.debug_mode === 'launch') {