pxt-core 11.3.9 → 11.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/pxt.js CHANGED
@@ -97735,8 +97735,8 @@ var pxt;
97735
97735
  if (!data)
97736
97736
  pxt.aiTrackEvent(id);
97737
97737
  else {
97738
- const props = Object.assign({}, defaultProps) || {};
97739
- const measures = Object.assign({}, defaultMeasures) || {};
97738
+ const props = Object.assign({}, defaultProps);
97739
+ const measures = Object.assign({}, defaultMeasures);
97740
97740
  Object.keys(data).forEach(k => {
97741
97741
  if (typeof data[k] == "string")
97742
97742
  props[k] = data[k];
@@ -99844,6 +99844,11 @@ var ts;
99844
99844
  function requestAsync(options) {
99845
99845
  //if (debugHttpRequests)
99846
99846
  // pxt.debug(`>> ${options.method || "GET"} ${options.url.replace(/[?#].*/, "...")}`); // don't leak secrets in logs
99847
+ const measureParams = {
99848
+ "url": `${encodeURI(options.url.replace(/[?#].*/, "..."))}`,
99849
+ "method": `${options.method || "GET"}`
99850
+ };
99851
+ pxt.perf.measureStart(Measurements.NetworkRequest);
99847
99852
  return Util.httpRequestCoreAsync(options)
99848
99853
  .then(resp => {
99849
99854
  //if (debugHttpRequests)
@@ -99859,6 +99864,25 @@ var ts;
99859
99864
  if (resp.text && /application\/json/.test(resp.headers["content-type"]))
99860
99865
  resp.json = pxtc.U.jsonTryParse(resp.text);
99861
99866
  return resp;
99867
+ })
99868
+ .then(resp => {
99869
+ const contentLength = resp.headers["content-length"];
99870
+ if (contentLength) {
99871
+ measureParams["sizeInBytes"] = `${contentLength}`;
99872
+ }
99873
+ else if (resp.text) {
99874
+ if (pxt.perf.isEnabled()) {
99875
+ // only do this work if perf measurement is actually enabled
99876
+ const encoder = new TextEncoder();
99877
+ const encoded = encoder.encode(resp.text);
99878
+ measureParams["sizeInBytes"] = encoded.length + "";
99879
+ }
99880
+ }
99881
+ measureParams["statusCode"] = `${resp.statusCode}`;
99882
+ return resp;
99883
+ })
99884
+ .finally(() => {
99885
+ pxt.perf.measureEnd(Measurements.NetworkRequest, measureParams);
99862
99886
  });
99863
99887
  }
99864
99888
  Util.requestAsync = requestAsync;
@@ -100890,9 +100914,9 @@ var ts;
100890
100914
  }
100891
100915
  BrowserImpl.sha256buffer = sha256buffer;
100892
100916
  function sha256string(s) {
100893
- pxt.perf.measureStart("sha256buffer");
100917
+ pxt.perf.measureStart(Measurements.Sha256Buffer);
100894
100918
  const res = sha256buffer(pxtc.Util.toUTF8Array(s));
100895
- pxt.perf.measureEnd("sha256buffer");
100919
+ pxt.perf.measureEnd(Measurements.Sha256Buffer);
100896
100920
  return res;
100897
100921
  }
100898
100922
  BrowserImpl.sha256string = sha256string;
@@ -101293,6 +101317,8 @@ var pxt;
101293
101317
  (function () {
101294
101318
  // Sometimes these aren't initialized, for example in tests. We only care about them
101295
101319
  // doing anything in the browser.
101320
+ if (!pxt.perf.isEnabled)
101321
+ pxt.perf.isEnabled = () => false;
101296
101322
  if (!pxt.perf.report)
101297
101323
  pxt.perf.report = () => undefined;
101298
101324
  if (!pxt.perf.recordMilestone)
@@ -101521,7 +101547,7 @@ var pxt;
101521
101547
  }
101522
101548
  }
101523
101549
  function reloadAppTargetVariant(temporary = false) {
101524
- pxt.perf.measureStart("reloadAppTargetVariant");
101550
+ pxt.perf.measureStart(Measurements.ReloadAppTargetVariant);
101525
101551
  const curr = temporary ? "" : JSON.stringify(pxt.appTarget);
101526
101552
  pxt.appTarget = pxt.U.cloneTargetBundle(savedAppTarget);
101527
101553
  if (pxt.appTargetVariant) {
@@ -101535,7 +101561,7 @@ var pxt;
101535
101561
  // check if apptarget changed
101536
101562
  if (!temporary && pxt.onAppTargetChanged && curr != JSON.stringify(pxt.appTarget))
101537
101563
  pxt.onAppTargetChanged();
101538
- pxt.perf.measureEnd("reloadAppTargetVariant");
101564
+ pxt.perf.measureEnd(Measurements.ReloadAppTargetVariant);
101539
101565
  }
101540
101566
  pxt.reloadAppTargetVariant = reloadAppTargetVariant;
101541
101567
  // this is set by compileServiceVariant in pxt.json
@@ -103573,13 +103599,13 @@ var pxt;
103573
103599
  });
103574
103600
  }
103575
103601
  setAsync(filename, snippets, code, highlights, codeValidationMap, branch) {
103576
- pxt.perf.measureStart("tutorial info db setAsync");
103602
+ pxt.perf.measureStart(Measurements.TutorialInfoDbSetAsync);
103577
103603
  const key = getTutorialInfoKey(filename, branch);
103578
103604
  const hash = getTutorialCodeHash(code);
103579
103605
  return this.setWithHashAsync(filename, snippets, hash, highlights, codeValidationMap);
103580
103606
  }
103581
103607
  setWithHashAsync(filename, snippets, hash, highlights, codeValidationMap, branch) {
103582
- pxt.perf.measureStart("tutorial info db setAsync");
103608
+ pxt.perf.measureStart(Measurements.TutorialInfoDbSetAsync);
103583
103609
  const key = getTutorialInfoKey(filename, branch);
103584
103610
  const blocks = {};
103585
103611
  Object.keys(snippets).forEach(hash => {
@@ -103598,7 +103624,7 @@ var pxt;
103598
103624
  };
103599
103625
  return this.db.setAsync(TutorialInfoIndexedDb.TABLE, entry)
103600
103626
  .then(() => {
103601
- pxt.perf.measureEnd("tutorial info db setAsync");
103627
+ pxt.perf.measureEnd(Measurements.TutorialInfoDbSetAsync);
103602
103628
  });
103603
103629
  }
103604
103630
  clearAsync() {
@@ -103953,6 +103979,8 @@ var pxt;
103953
103979
  commands.electronDeployAsync = undefined; // A pointer to the Electron deploy function, so that targets can access it in their extension.ts
103954
103980
  commands.webUsbPairDialogAsync = undefined;
103955
103981
  commands.onTutorialCompleted = undefined;
103982
+ commands.onPerfMilestone = undefined;
103983
+ commands.onPerfMeasurement = undefined;
103956
103984
  commands.workspaceLoadedAsync = undefined;
103957
103985
  commands.onMarkdownActivityLoad = undefined;
103958
103986
  })(commands = pxt.commands || (pxt.commands = {}));
@@ -104052,6 +104080,14 @@ var pxt;
104052
104080
  return ("0" + n.toString(16)).slice(-2);
104053
104081
  }
104054
104082
  })(pxt || (pxt = {}));
104083
+ var Measurements;
104084
+ (function (Measurements) {
104085
+ Measurements.TutorialInfoDbSetAsync = "tutorial info db setAsync";
104086
+ Measurements.ReloadAppTargetVariant = "reloadAppTargetVariant";
104087
+ Measurements.Sha256Buffer = "sha256buffer";
104088
+ Measurements.WebworkerRecvHandler = "webworker recvHandler";
104089
+ Measurements.NetworkRequest = "network.request";
104090
+ })(Measurements || (Measurements = {}));
104055
104091
  /// <reference path="../localtypings/pxtarget.d.ts"/>
104056
104092
  var pxt;
104057
104093
  (function (pxt) {
@@ -121097,9 +121133,9 @@ var pxt;
121097
121133
  let worker = new Worker(workerFile);
121098
121134
  let iface = wrap(v => worker.postMessage(v));
121099
121135
  worker.onmessage = ev => {
121100
- pxt.perf.measureStart("webworker recvHandler");
121136
+ pxt.perf.measureStart(Measurements.WebworkerRecvHandler);
121101
121137
  iface.recvHandler(ev.data);
121102
- pxt.perf.measureEnd("webworker recvHandler");
121138
+ pxt.perf.measureEnd(Measurements.WebworkerRecvHandler);
121103
121139
  };
121104
121140
  return iface;
121105
121141
  }
package/built/pxtlib.d.ts CHANGED
@@ -523,6 +523,10 @@ declare namespace ts.pxtc.jsonPatch.tests {
523
523
  function patchTests(): void;
524
524
  }
525
525
  declare namespace pxt.perf {
526
+ type EventSource<T> = {
527
+ subscribe(listener: (payload: T) => void): () => void;
528
+ };
529
+ function isEnabled(): boolean;
526
530
  let perfReportLogged: boolean;
527
531
  function report(): {
528
532
  milestones: {
@@ -532,9 +536,20 @@ declare namespace pxt.perf {
532
536
  [index: string]: number;
533
537
  };
534
538
  } | undefined;
535
- function recordMilestone(msg: string, time?: number): void;
539
+ function recordMilestone(msg: string, params?: Map<string>): void;
536
540
  function measureStart(name: string): void;
537
- function measureEnd(name: string): void;
541
+ function measureEnd(name: string, params?: Map<string>): void;
542
+ const onMilestone: EventSource<{
543
+ milestone: string;
544
+ time: number;
545
+ params?: Map<string>;
546
+ }>;
547
+ const onMeasurement: EventSource<{
548
+ name: string;
549
+ start: number;
550
+ duration: number;
551
+ params?: Map<string>;
552
+ }>;
538
553
  }
539
554
  declare namespace pxt {
540
555
  export import U = pxtc.Util;
@@ -1007,6 +1022,18 @@ declare namespace pxt.commands {
1007
1022
  let electronDeployAsync: (r: ts.pxtc.CompileResult) => Promise<void>;
1008
1023
  let webUsbPairDialogAsync: (pairAsync: () => Promise<boolean>, confirmAsync: (options: any) => Promise<WebUSBPairResult>, implicitlyCalled?: boolean) => Promise<WebUSBPairResult>;
1009
1024
  let onTutorialCompleted: () => void;
1025
+ let onPostHostMessage: (msg: any) => void;
1026
+ let onPerfMilestone: (payload: {
1027
+ milestone: string;
1028
+ time: number;
1029
+ params?: Map<string>;
1030
+ }) => void;
1031
+ let onPerfMeasurement: (payload: {
1032
+ name: string;
1033
+ start: number;
1034
+ duration: number;
1035
+ params?: Map<string>;
1036
+ }) => void;
1010
1037
  let workspaceLoadedAsync: () => Promise<void>;
1011
1038
  let onMarkdownActivityLoad: (path: string, title?: string, editorProjectName?: string) => Promise<void>;
1012
1039
  }
@@ -1014,6 +1041,13 @@ declare namespace pxt {
1014
1041
  function getWhiteContrastingBackground(color: string): string;
1015
1042
  function contrastRatio(fg: string, bg: string): number;
1016
1043
  }
1044
+ declare namespace Measurements {
1045
+ const TutorialInfoDbSetAsync = "tutorial info db setAsync";
1046
+ const ReloadAppTargetVariant = "reloadAppTargetVariant";
1047
+ const Sha256Buffer = "sha256buffer";
1048
+ const WebworkerRecvHandler = "webworker recvHandler";
1049
+ const NetworkRequest = "network.request";
1050
+ }
1017
1051
  declare namespace pxt {
1018
1052
  function lzmaDecompressAsync(buf: Uint8Array): Promise<string>;
1019
1053
  function lzmaCompressAsync(text: string): Promise<Uint8Array>;
package/built/pxtlib.js CHANGED
@@ -49,8 +49,8 @@ var pxt;
49
49
  if (!data)
50
50
  pxt.aiTrackEvent(id);
51
51
  else {
52
- const props = Object.assign({}, defaultProps) || {};
53
- const measures = Object.assign({}, defaultMeasures) || {};
52
+ const props = Object.assign({}, defaultProps);
53
+ const measures = Object.assign({}, defaultMeasures);
54
54
  Object.keys(data).forEach(k => {
55
55
  if (typeof data[k] == "string")
56
56
  props[k] = data[k];
@@ -2158,6 +2158,11 @@ var ts;
2158
2158
  function requestAsync(options) {
2159
2159
  //if (debugHttpRequests)
2160
2160
  // pxt.debug(`>> ${options.method || "GET"} ${options.url.replace(/[?#].*/, "...")}`); // don't leak secrets in logs
2161
+ const measureParams = {
2162
+ "url": `${encodeURI(options.url.replace(/[?#].*/, "..."))}`,
2163
+ "method": `${options.method || "GET"}`
2164
+ };
2165
+ pxt.perf.measureStart(Measurements.NetworkRequest);
2161
2166
  return Util.httpRequestCoreAsync(options)
2162
2167
  .then(resp => {
2163
2168
  //if (debugHttpRequests)
@@ -2173,6 +2178,25 @@ var ts;
2173
2178
  if (resp.text && /application\/json/.test(resp.headers["content-type"]))
2174
2179
  resp.json = pxtc.U.jsonTryParse(resp.text);
2175
2180
  return resp;
2181
+ })
2182
+ .then(resp => {
2183
+ const contentLength = resp.headers["content-length"];
2184
+ if (contentLength) {
2185
+ measureParams["sizeInBytes"] = `${contentLength}`;
2186
+ }
2187
+ else if (resp.text) {
2188
+ if (pxt.perf.isEnabled()) {
2189
+ // only do this work if perf measurement is actually enabled
2190
+ const encoder = new TextEncoder();
2191
+ const encoded = encoder.encode(resp.text);
2192
+ measureParams["sizeInBytes"] = encoded.length + "";
2193
+ }
2194
+ }
2195
+ measureParams["statusCode"] = `${resp.statusCode}`;
2196
+ return resp;
2197
+ })
2198
+ .finally(() => {
2199
+ pxt.perf.measureEnd(Measurements.NetworkRequest, measureParams);
2176
2200
  });
2177
2201
  }
2178
2202
  Util.requestAsync = requestAsync;
@@ -3204,9 +3228,9 @@ var ts;
3204
3228
  }
3205
3229
  BrowserImpl.sha256buffer = sha256buffer;
3206
3230
  function sha256string(s) {
3207
- pxt.perf.measureStart("sha256buffer");
3231
+ pxt.perf.measureStart(Measurements.Sha256Buffer);
3208
3232
  const res = sha256buffer(pxtc.Util.toUTF8Array(s));
3209
- pxt.perf.measureEnd("sha256buffer");
3233
+ pxt.perf.measureEnd(Measurements.Sha256Buffer);
3210
3234
  return res;
3211
3235
  }
3212
3236
  BrowserImpl.sha256string = sha256string;
@@ -3607,6 +3631,8 @@ var pxt;
3607
3631
  (function () {
3608
3632
  // Sometimes these aren't initialized, for example in tests. We only care about them
3609
3633
  // doing anything in the browser.
3634
+ if (!pxt.perf.isEnabled)
3635
+ pxt.perf.isEnabled = () => false;
3610
3636
  if (!pxt.perf.report)
3611
3637
  pxt.perf.report = () => undefined;
3612
3638
  if (!pxt.perf.recordMilestone)
@@ -3835,7 +3861,7 @@ var pxt;
3835
3861
  }
3836
3862
  }
3837
3863
  function reloadAppTargetVariant(temporary = false) {
3838
- pxt.perf.measureStart("reloadAppTargetVariant");
3864
+ pxt.perf.measureStart(Measurements.ReloadAppTargetVariant);
3839
3865
  const curr = temporary ? "" : JSON.stringify(pxt.appTarget);
3840
3866
  pxt.appTarget = pxt.U.cloneTargetBundle(savedAppTarget);
3841
3867
  if (pxt.appTargetVariant) {
@@ -3849,7 +3875,7 @@ var pxt;
3849
3875
  // check if apptarget changed
3850
3876
  if (!temporary && pxt.onAppTargetChanged && curr != JSON.stringify(pxt.appTarget))
3851
3877
  pxt.onAppTargetChanged();
3852
- pxt.perf.measureEnd("reloadAppTargetVariant");
3878
+ pxt.perf.measureEnd(Measurements.ReloadAppTargetVariant);
3853
3879
  }
3854
3880
  pxt.reloadAppTargetVariant = reloadAppTargetVariant;
3855
3881
  // this is set by compileServiceVariant in pxt.json
@@ -5887,13 +5913,13 @@ var pxt;
5887
5913
  });
5888
5914
  }
5889
5915
  setAsync(filename, snippets, code, highlights, codeValidationMap, branch) {
5890
- pxt.perf.measureStart("tutorial info db setAsync");
5916
+ pxt.perf.measureStart(Measurements.TutorialInfoDbSetAsync);
5891
5917
  const key = getTutorialInfoKey(filename, branch);
5892
5918
  const hash = getTutorialCodeHash(code);
5893
5919
  return this.setWithHashAsync(filename, snippets, hash, highlights, codeValidationMap);
5894
5920
  }
5895
5921
  setWithHashAsync(filename, snippets, hash, highlights, codeValidationMap, branch) {
5896
- pxt.perf.measureStart("tutorial info db setAsync");
5922
+ pxt.perf.measureStart(Measurements.TutorialInfoDbSetAsync);
5897
5923
  const key = getTutorialInfoKey(filename, branch);
5898
5924
  const blocks = {};
5899
5925
  Object.keys(snippets).forEach(hash => {
@@ -5912,7 +5938,7 @@ var pxt;
5912
5938
  };
5913
5939
  return this.db.setAsync(TutorialInfoIndexedDb.TABLE, entry)
5914
5940
  .then(() => {
5915
- pxt.perf.measureEnd("tutorial info db setAsync");
5941
+ pxt.perf.measureEnd(Measurements.TutorialInfoDbSetAsync);
5916
5942
  });
5917
5943
  }
5918
5944
  clearAsync() {
@@ -6267,6 +6293,8 @@ var pxt;
6267
6293
  commands.electronDeployAsync = undefined; // A pointer to the Electron deploy function, so that targets can access it in their extension.ts
6268
6294
  commands.webUsbPairDialogAsync = undefined;
6269
6295
  commands.onTutorialCompleted = undefined;
6296
+ commands.onPerfMilestone = undefined;
6297
+ commands.onPerfMeasurement = undefined;
6270
6298
  commands.workspaceLoadedAsync = undefined;
6271
6299
  commands.onMarkdownActivityLoad = undefined;
6272
6300
  })(commands = pxt.commands || (pxt.commands = {}));
@@ -6366,6 +6394,14 @@ var pxt;
6366
6394
  return ("0" + n.toString(16)).slice(-2);
6367
6395
  }
6368
6396
  })(pxt || (pxt = {}));
6397
+ var Measurements;
6398
+ (function (Measurements) {
6399
+ Measurements.TutorialInfoDbSetAsync = "tutorial info db setAsync";
6400
+ Measurements.ReloadAppTargetVariant = "reloadAppTargetVariant";
6401
+ Measurements.Sha256Buffer = "sha256buffer";
6402
+ Measurements.WebworkerRecvHandler = "webworker recvHandler";
6403
+ Measurements.NetworkRequest = "network.request";
6404
+ })(Measurements || (Measurements = {}));
6369
6405
  /// <reference path="../localtypings/pxtarget.d.ts"/>
6370
6406
  var pxt;
6371
6407
  (function (pxt) {
@@ -23411,9 +23447,9 @@ var pxt;
23411
23447
  let worker = new Worker(workerFile);
23412
23448
  let iface = wrap(v => worker.postMessage(v));
23413
23449
  worker.onmessage = ev => {
23414
- pxt.perf.measureStart("webworker recvHandler");
23450
+ pxt.perf.measureStart(Measurements.WebworkerRecvHandler);
23415
23451
  iface.recvHandler(ev.data);
23416
- pxt.perf.measureEnd("webworker recvHandler");
23452
+ pxt.perf.measureEnd(Measurements.WebworkerRecvHandler);
23417
23453
  };
23418
23454
  return iface;
23419
23455
  }