viztracer 1.1.0__cp314-cp314-win32.whl

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.

Potentially problematic release.


This version of viztracer might be problematic. Click here for more details.

Files changed (109) hide show
  1. viztracer/__init__.py +19 -0
  2. viztracer/__main__.py +8 -0
  3. viztracer/attach.py +67 -0
  4. viztracer/attach_process/LICENSE +203 -0
  5. viztracer/attach_process/__init__.py +0 -0
  6. viztracer/attach_process/add_code_to_python_process.py +582 -0
  7. viztracer/attach_process/attach_x86.dll +0 -0
  8. viztracer/attach_process/inject_dll_amd64.exe +0 -0
  9. viztracer/attach_process/linux_and_mac/lldb_prepare.py +54 -0
  10. viztracer/attach_process/run_code_on_dllmain_amd64.dll +0 -0
  11. viztracer/attach_process/run_code_on_dllmain_x86.dll +0 -0
  12. viztracer/cellmagic.py +70 -0
  13. viztracer/code_monkey.py +353 -0
  14. viztracer/decorator.py +164 -0
  15. viztracer/event_base.py +81 -0
  16. viztracer/functree.py +135 -0
  17. viztracer/html/flamegraph.html +34 -0
  18. viztracer/html/trace_viewer_embedder.html +203 -0
  19. viztracer/html/trace_viewer_full.html +10207 -0
  20. viztracer/main.py +699 -0
  21. viztracer/modules/eventnode.c +172 -0
  22. viztracer/modules/eventnode.h +73 -0
  23. viztracer/modules/pythoncapi_compat.h +1726 -0
  24. viztracer/modules/quicktime.c +177 -0
  25. viztracer/modules/quicktime.h +104 -0
  26. viztracer/modules/snaptrace.c +2205 -0
  27. viztracer/modules/snaptrace.h +134 -0
  28. viztracer/modules/snaptrace_member.c +483 -0
  29. viztracer/modules/util.c +45 -0
  30. viztracer/modules/util.h +22 -0
  31. viztracer/modules/vcompressor/vc_dump.c +1131 -0
  32. viztracer/modules/vcompressor/vc_dump.h +49 -0
  33. viztracer/modules/vcompressor/vcompressor.c +396 -0
  34. viztracer/modules/vcompressor/vcompressor.h +15 -0
  35. viztracer/patch.py +307 -0
  36. viztracer/report_builder.py +311 -0
  37. viztracer/snaptrace.cp314-win32.pyd +0 -0
  38. viztracer/snaptrace.pyi +77 -0
  39. viztracer/util.py +196 -0
  40. viztracer/vcompressor.cp314-win32.pyd +0 -0
  41. viztracer/vcompressor.pyi +10 -0
  42. viztracer/viewer.py +528 -0
  43. viztracer/vizcounter.py +20 -0
  44. viztracer/vizevent.py +31 -0
  45. viztracer/vizlogging.py +20 -0
  46. viztracer/vizobject.py +28 -0
  47. viztracer/vizplugin.py +143 -0
  48. viztracer/viztracer.py +472 -0
  49. viztracer/web_dist/LICENSE +189 -0
  50. viztracer/web_dist/index.html +127 -0
  51. viztracer/web_dist/service_worker.js +279 -0
  52. viztracer/web_dist/trace_processor +300 -0
  53. viztracer/web_dist/v52.0-6b9586def/assets/MaterialSymbolsOutlined.woff2 +0 -0
  54. viztracer/web_dist/v52.0-6b9586def/assets/Roboto-100.woff2 +0 -0
  55. viztracer/web_dist/v52.0-6b9586def/assets/Roboto-300.woff2 +0 -0
  56. viztracer/web_dist/v52.0-6b9586def/assets/Roboto-400.woff2 +0 -0
  57. viztracer/web_dist/v52.0-6b9586def/assets/Roboto-500.woff2 +0 -0
  58. viztracer/web_dist/v52.0-6b9586def/assets/RobotoCondensed-Light.woff2 +0 -0
  59. viztracer/web_dist/v52.0-6b9586def/assets/RobotoCondensed-Regular.woff2 +0 -0
  60. viztracer/web_dist/v52.0-6b9586def/assets/RobotoMono-Regular.woff2 +0 -0
  61. viztracer/web_dist/v52.0-6b9586def/assets/brand.png +0 -0
  62. viztracer/web_dist/v52.0-6b9586def/assets/catapult_trace_viewer.html +3946 -0
  63. viztracer/web_dist/v52.0-6b9586def/assets/catapult_trace_viewer.js +7539 -0
  64. viztracer/web_dist/v52.0-6b9586def/assets/favicon.png +0 -0
  65. viztracer/web_dist/v52.0-6b9586def/assets/logo-128.png +0 -0
  66. viztracer/web_dist/v52.0-6b9586def/assets/logo-3d.png +0 -0
  67. viztracer/web_dist/v52.0-6b9586def/assets/rec_atrace.png +0 -0
  68. viztracer/web_dist/v52.0-6b9586def/assets/rec_battery_counters.png +0 -0
  69. viztracer/web_dist/v52.0-6b9586def/assets/rec_board_voltage.png +0 -0
  70. viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_coarse.png +0 -0
  71. viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_fine.png +0 -0
  72. viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_freq.png +0 -0
  73. viztracer/web_dist/v52.0-6b9586def/assets/rec_cpu_voltage.png +0 -0
  74. viztracer/web_dist/v52.0-6b9586def/assets/rec_frame_timeline.png +0 -0
  75. viztracer/web_dist/v52.0-6b9586def/assets/rec_ftrace.png +0 -0
  76. viztracer/web_dist/v52.0-6b9586def/assets/rec_gpu_mem_total.png +0 -0
  77. viztracer/web_dist/v52.0-6b9586def/assets/rec_java_heap_dump.png +0 -0
  78. viztracer/web_dist/v52.0-6b9586def/assets/rec_lmk.png +0 -0
  79. viztracer/web_dist/v52.0-6b9586def/assets/rec_logcat.png +0 -0
  80. viztracer/web_dist/v52.0-6b9586def/assets/rec_long_trace.png +0 -0
  81. viztracer/web_dist/v52.0-6b9586def/assets/rec_mem_hifreq.png +0 -0
  82. viztracer/web_dist/v52.0-6b9586def/assets/rec_meminfo.png +0 -0
  83. viztracer/web_dist/v52.0-6b9586def/assets/rec_native_heap_profiler.png +0 -0
  84. viztracer/web_dist/v52.0-6b9586def/assets/rec_one_shot.png +0 -0
  85. viztracer/web_dist/v52.0-6b9586def/assets/rec_profiling.png +0 -0
  86. viztracer/web_dist/v52.0-6b9586def/assets/rec_ps_stats.png +0 -0
  87. viztracer/web_dist/v52.0-6b9586def/assets/rec_ring_buf.png +0 -0
  88. viztracer/web_dist/v52.0-6b9586def/assets/rec_syscalls.png +0 -0
  89. viztracer/web_dist/v52.0-6b9586def/assets/rec_vmstat.png +0 -0
  90. viztracer/web_dist/v52.0-6b9586def/assets/scheduling_latency.png +0 -0
  91. viztracer/web_dist/v52.0-6b9586def/assets/vscode-icon.png +0 -0
  92. viztracer/web_dist/v52.0-6b9586def/engine_bundle.js +3 -0
  93. viztracer/web_dist/v52.0-6b9586def/frontend_bundle.js +5495 -0
  94. viztracer/web_dist/v52.0-6b9586def/index.html +127 -0
  95. viztracer/web_dist/v52.0-6b9586def/manifest.json +52 -0
  96. viztracer/web_dist/v52.0-6b9586def/perfetto.css +5737 -0
  97. viztracer/web_dist/v52.0-6b9586def/stdlib_docs.json +1 -0
  98. viztracer/web_dist/v52.0-6b9586def/trace_config_utils.wasm +0 -0
  99. viztracer/web_dist/v52.0-6b9586def/trace_processor.wasm +0 -0
  100. viztracer/web_dist/v52.0-6b9586def/trace_processor_memory64.wasm +0 -0
  101. viztracer/web_dist/v52.0-6b9586def/traceconv.wasm +0 -0
  102. viztracer/web_dist/v52.0-6b9586def/traceconv_bundle.js +2 -0
  103. viztracer-1.1.0.dist-info/METADATA +316 -0
  104. viztracer-1.1.0.dist-info/RECORD +109 -0
  105. viztracer-1.1.0.dist-info/WHEEL +5 -0
  106. viztracer-1.1.0.dist-info/entry_points.txt +3 -0
  107. viztracer-1.1.0.dist-info/licenses/LICENSE +222 -0
  108. viztracer-1.1.0.dist-info/licenses/NOTICE.txt +27 -0
  109. viztracer-1.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (c) 2017, The Android Open Source Project
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+
183
+ Unless required by applicable law or agreed to in writing, software
184
+ distributed under the License is distributed on an "AS IS" BASIS,
185
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
186
+ See the License for the specific language governing permissions and
187
+ limitations under the License.
188
+
189
+
@@ -0,0 +1,127 @@
1
+ <!doctype html>
2
+ <html lang="en-us">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Perfetto UI</title>
6
+ <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
7
+ <link rel="shortcut icon" id="favicon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
8
+ </head>
9
+ <body data-perfetto_version='{"stable":"v52.0-6b9586def"}'>
10
+ <!--
11
+ Don't add any content here. The whole <body> is replaced by
12
+ frontend/index.ts when bootstrapping. This is only used for very early
13
+ error reporting.
14
+ -->
15
+ <style>
16
+ #app_load_failure {opacity:0;transition:opacity 1s ease;position:absolute;overflow:auto;background:#080082;top:0;left:0;width:100%;height:100%;bottom:0;right:0;margin:0;opacity:0;user-select:text}
17
+ #app_load_failure > pre {color:#fff;position:absolute;margin:auto;white-space:pre-wrap;top:10vh;max-width:90vw;width:880px;left:0;right:0;font-size:16px;line-height:30px;font-weight:700}
18
+ #app_load_failure > pre span {background:#fff;color:#080082;padding:2px}
19
+ #app_load_failure_dbg { overflow-wrap: break-word; font-size: 12px; line-height: 1; font-weight: initial;}
20
+ #app_load_failure a {color:#fff}
21
+ #app_load { position: absolute; top: 0; left: 0; right:0; bottom: 0; background-color: #2c3e50;}
22
+ #app_load_spinner { margin: 30vh auto; width: 150px; height: 150px; border: 3px solid rgba(255,255,255,.3); border-radius: 50%; border-top-color: #fff; animation: app_load_spin 1s ease-in-out infinite; }
23
+ @keyframes app_load_spin { to { transform: rotate(360deg); } }
24
+ </style>
25
+ <div id="app_load"><div id="app_load_spinner"></div></div>
26
+ <div id="app_load_failure">
27
+ <pre>
28
+ <span>Perfetto UI - An unrecoverable problem occurred</span>
29
+
30
+ If you are seeing this message, something went wrong while loading the UI.
31
+ In most cases this is due to very slow or flaky network and it goes away by
32
+ disabling and re-enabling WiFi or trying reloading.
33
+
34
+ If the problem persists try these remediation steps:
35
+
36
+ * Force-reload the page with Ctrl+Shift+R (Mac: Meta+Shift+R) or
37
+ Shift + click on the refresh button.
38
+
39
+ * <a href="javascript:clearAllCaches();">Clear all the site storage and caches</a> and reload the page.
40
+
41
+ * Clear the site data and caches from devtools, following <a target="_blank" href="https://developers.google.com/web/tools/chrome-devtools/storage/cache#deletecache">these instructions</a>.
42
+
43
+ If none of this works, file a bug attaching logs and screenshots from devtools.
44
+ Googlers: <a href="http://go/perfetto-ui-bug" target="_blank">go/perfetto-ui-bug</a>
45
+ Non-googlers: <a href="https://github.com/google/perfetto/issues/new" target="_blank">github.com/google/perfetto/issues/new</a>
46
+
47
+ <div id=app_load_failure_err></div>
48
+ Technical Information:
49
+ <div id=app_load_failure_dbg></div>
50
+ </pre>
51
+ </div>
52
+ <script type="text/javascript">
53
+ 'use strict';
54
+ (function () {
55
+ const TIMEOUT_MS = 120000;
56
+ let errTimerId = undefined;
57
+
58
+ function errHandler(err) {
59
+ // Note: we deliberately don't clearTimeout(), which means that this
60
+ // handler is called also in the happy case when the UI loads. In that
61
+ // case, though, the onCssLoaded() in frontend/index.ts will empty the
62
+ // <body>, so |div| below will be null and this function becomes a
63
+ // no-op.
64
+ const div = document.getElementById('app_load_failure');
65
+ if (!div) return;
66
+ div.style.opacity ='1';
67
+ const errDom = document.getElementById('app_load_failure_err');
68
+ if (!errDom) return;
69
+ console.error(err);
70
+ errDom.innerText += `${err}\n`;
71
+ const storageJson = JSON.stringify(window.localStorage);
72
+ const dbg = document.getElementById('app_load_failure_dbg');
73
+ if (!dbg) return;
74
+ dbg.innerText = `LocalStorage: ${storageJson}\n`;
75
+ if (errTimerId !== undefined) clearTimeout(errTimerId);
76
+ }
77
+
78
+ // For the 'Click here to clear all caches'.
79
+ window.clearAllCaches = async () => {
80
+ if (window.localStorage) window.localStorage.clear();
81
+ if (window.sessionStorage) window.sessionStorage.clear();
82
+ const promises = [];
83
+ if (window.caches) {
84
+ try {
85
+ const keys = await window.caches.keys();
86
+ keys.forEach(k => promises.push(window.caches.delete(k)));
87
+ } catch (_) {
88
+ // TODO(288483453)
89
+ }
90
+ }
91
+ if (navigator.serviceWorker) {
92
+ const regs = await navigator.serviceWorker.getRegistrations();
93
+ regs.forEach(reg => promises.push(reg.unregister()));
94
+ }
95
+ try {
96
+ await Promise.all(promises);
97
+ } catch (_) {
98
+ // TODO(288483453)
99
+ }
100
+ window.location.reload();
101
+ }
102
+
103
+ // If the frontend doesn't come up, make the error page above visible.
104
+ errTimerId = setTimeout(() => errHandler('Timed out'), TIMEOUT_MS);
105
+ window.onerror = errHandler;
106
+ window.onunhandledrejection = errHandler;
107
+
108
+ const versionStr = document.body.dataset['perfetto_version'] || '{}';
109
+ const versionMap = JSON.parse(versionStr);
110
+ const channel = localStorage.getItem('perfettoUiChannel') || 'stable';
111
+
112
+ // The '.' below is a fallback for the case of opening a pinned version
113
+ // (e.g., ui.perfetto.dev/v1.2.3./). In that case, the index.html has no
114
+ // valid version map; we want to load the frontend from the same
115
+ // sub-directory directory, hence ./frontend_bundle.js.
116
+ const version = versionMap[channel] || versionMap['stable'] || '.';
117
+
118
+ const script = document.createElement('script');
119
+ script.async = true;
120
+ script.src = version + '/frontend_bundle.js';
121
+ script.onerror = () => errHandler(`Failed to load ${script.src}`);
122
+
123
+ document.head.append(script);
124
+ })();
125
+ </script>
126
+ </body>
127
+ </html>
@@ -0,0 +1,279 @@
1
+ var service_worker = (function () {
2
+ 'use strict';
3
+
4
+ var service_worker = {};
5
+
6
+ // Copyright (C) 2020 The Android Open Source Project
7
+ //
8
+ // Licensed under the Apache License, Version 2.0 (the "License");
9
+ // you may not use this file except in compliance with the License.
10
+ // You may obtain a copy of the License at
11
+ //
12
+ // http://www.apache.org/licenses/LICENSE-2.0
13
+ //
14
+ // Unless required by applicable law or agreed to in writing, software
15
+ // distributed under the License is distributed on an "AS IS" BASIS,
16
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ // See the License for the specific language governing permissions and
18
+ // limitations under the License.
19
+ Object.defineProperty(service_worker, "__esModule", { value: true });
20
+ const LOG_TAG = `ServiceWorker: `;
21
+ const CACHE_NAME = 'ui-perfetto-dev';
22
+ const OPEN_TRACE_PREFIX = '/_open_trace';
23
+ // If the fetch() for the / doesn't respond within 3s, return a cached version.
24
+ // This is to avoid that a user waits too much if on a flaky network.
25
+ const INDEX_TIMEOUT_MS = 3000;
26
+ // Use more relaxed timeouts when caching the subresources for the new version
27
+ // in the background.
28
+ const INSTALL_TIMEOUT_MS = 30000;
29
+ // Files passed to POST /_open_trace/NNNN.
30
+ let postedFiles = new Map();
31
+ // The install() event is fired:
32
+ // 1. On the first visit, when there is no SW installed.
33
+ // 2. Every time the user opens the site and the version has been updated (they
34
+ // will get the newer version regardless, unless we hit INDEX_TIMEOUT_MS).
35
+ // The latter happens because:
36
+ // - / (index.html) is always served from the network (% timeout) and it pulls
37
+ // /v1.2-sha/frontend_bundle.js.
38
+ // - /v1.2-sha/frontend_bundle.js will register /service_worker.js?v=v1.2-sha.
39
+ // The service_worker.js script itself never changes, but the browser
40
+ // re-installs it because the version in the V? query-string argument changes.
41
+ // The reinstallation will cache the new files from the v.1.2-sha/manifest.json.
42
+ self.addEventListener('install', (event) => {
43
+ const doInstall = async () => {
44
+ // If we can not access the cache we must give up on the service
45
+ // worker:
46
+ let bypass = true;
47
+ try {
48
+ bypass = await caches.has('BYPASS_SERVICE_WORKER');
49
+ }
50
+ catch (_) {
51
+ // TODO(288483453)
52
+ }
53
+ if (bypass) {
54
+ // Throw will prevent the installation.
55
+ throw new Error(LOG_TAG + 'skipping installation, bypass enabled');
56
+ }
57
+ // Delete old cache entries from the pre-feb-2021 service worker.
58
+ try {
59
+ for (const key of await caches.keys()) {
60
+ if (key.startsWith('dist-')) {
61
+ await caches.delete(key);
62
+ }
63
+ }
64
+ }
65
+ catch (_) {
66
+ // TODO(288483453)
67
+ // It's desirable to delete the old entries but it's not actually
68
+ // damaging to keep them around so don't give up on the
69
+ // installation if this fails.
70
+ }
71
+ // The UI should register this as service_worker.js?v=v1.2-sha. Extract the
72
+ // version number and pre-fetch all the contents for the version.
73
+ const match = /\bv=([\w.-]*)/.exec(location.search);
74
+ if (!match) {
75
+ throw new Error('Failed to install. Was epecting a query string like ' +
76
+ `?v=v1.2-sha query string, got "${location.search}" instead`);
77
+ }
78
+ await installAppVersionIntoCache(match[1]);
79
+ // skipWaiting() still waits for the install to be complete. Without this
80
+ // call, the new version would be activated only when all tabs are closed.
81
+ // Instead, we ask to activate it immediately. This is safe because the
82
+ // subresources are versioned (e.g. /v1.2-sha/frontend_bundle.js). Even if
83
+ // there is an old UI tab opened while we activate() a newer version, the
84
+ // activate() would just cause cache-misses, hence fetch from the network,
85
+ // for the old tab.
86
+ self.skipWaiting();
87
+ };
88
+ event.waitUntil(doInstall());
89
+ });
90
+ self.addEventListener('activate', (event) => {
91
+ console.info(LOG_TAG + 'activated');
92
+ const doActivate = async () => {
93
+ // This makes a difference only for the very first load, when no service
94
+ // worker is present. In all the other cases the skipWaiting() will hot-swap
95
+ // the active service worker anyways.
96
+ await self.clients.claim();
97
+ };
98
+ event.waitUntil(doActivate());
99
+ });
100
+ self.addEventListener('fetch', (event) => {
101
+ // The early return here will cause the browser to fall back on standard
102
+ // network-based fetch.
103
+ if (!shouldHandleHttpRequest(event.request)) {
104
+ console.debug(LOG_TAG + `serving ${event.request.url} from network`);
105
+ return;
106
+ }
107
+ event.respondWith(handleHttpRequest(event.request));
108
+ });
109
+ function shouldHandleHttpRequest(req) {
110
+ // Suppress warning: 'only-if-cached' can be set only with 'same-origin' mode.
111
+ // This seems to be a chromium bug. An internal code search suggests this is a
112
+ // socially acceptable workaround.
113
+ if (req.cache === 'only-if-cached' && req.mode !== 'same-origin') {
114
+ return false;
115
+ }
116
+ const url = new URL(req.url);
117
+ if (url.pathname === '/live_reload')
118
+ return false;
119
+ if (url.pathname.startsWith(OPEN_TRACE_PREFIX))
120
+ return true;
121
+ return req.method === 'GET' && url.origin === self.location.origin;
122
+ }
123
+ async function handleHttpRequest(req) {
124
+ if (!shouldHandleHttpRequest(req)) {
125
+ throw new Error(LOG_TAG + `${req.url} shouldn't have been handled`);
126
+ }
127
+ // We serve from the cache even if req.cache == 'no-cache'. It's a bit
128
+ // contra-intuitive but it's the most consistent option. If the user hits the
129
+ // reload button*, the browser requests the "/" index with a 'no-cache' fetch.
130
+ // However all the other resources (css, js, ...) are requested with a
131
+ // 'default' fetch (this is just how Chrome works, it's not us). If we bypass
132
+ // the service worker cache when we get a 'no-cache' request, we can end up in
133
+ // an inconsistent state where the index.html is more recent than the other
134
+ // resources, which is undesirable.
135
+ // * Only Ctrl+R. Ctrl+Shift+R will always bypass service-worker for all the
136
+ // requests (index.html and the rest) made in that tab.
137
+ const cacheOps = { cacheName: CACHE_NAME };
138
+ const url = new URL(req.url);
139
+ if (url.pathname === '/') {
140
+ try {
141
+ console.debug(LOG_TAG + `Fetching live ${req.url}`);
142
+ // The await bleow is needed to fall through in case of an exception.
143
+ return await fetchWithTimeout(req, INDEX_TIMEOUT_MS);
144
+ }
145
+ catch (err) {
146
+ console.warn(LOG_TAG + `Failed to fetch ${req.url}, using cache.`, err);
147
+ // Fall through the code below.
148
+ }
149
+ }
150
+ else if (url.pathname === '/offline') {
151
+ // Escape hatch to force serving the offline version without attempting the
152
+ // network fetch.
153
+ const cachedRes = await caches.match(new Request('/'), cacheOps);
154
+ if (cachedRes)
155
+ return cachedRes;
156
+ }
157
+ else if (url.pathname.startsWith(OPEN_TRACE_PREFIX)) {
158
+ return await handleOpenTraceRequest(req);
159
+ }
160
+ const cachedRes = await caches.match(req, cacheOps);
161
+ if (cachedRes) {
162
+ console.debug(LOG_TAG + `serving ${req.url} from cache`);
163
+ return cachedRes;
164
+ }
165
+ // In any other case, just propagate the fetch on the network, which is the
166
+ // safe behavior.
167
+ console.warn(LOG_TAG + `cache miss on ${req.url}, using live network`);
168
+ return fetch(req);
169
+ }
170
+ // Handles GET and POST requests to /_open_trace/NNNN, where NNNN is typically a
171
+ // random token generated by the client.
172
+ // This works as follows:
173
+ // - The client does a POST request to /_open_trace/NNNN passing the trace blob
174
+ // as multipart-data, alongside other options like hideSidebar & co that we
175
+ // support in the usual querystring (see router.ts)
176
+ // - The SW takes the file and puts it in the global variable `postedFiles`.
177
+ // - The SW responds to the POST request with a redirect to
178
+ // ui.perfetto.dev/#!/?url=https://ui.perfetto.dev/_open_trace/NNNN&other_args
179
+ // - When the new ui.perfetto.dev is reloaded, it will naturally try to fetch
180
+ // the trace from /_open_trace/NNNN, this time via a GET request.
181
+ // - The SW intercepts the GET request and returns the file previosly stored in
182
+ // `postedFiles`.
183
+ // We use postedFiles here to handle the case of progammatically POST-ing to >1
184
+ // instances of ui.perfetto.dev simultaneously, to avoid races.
185
+ // Note that we should not use a global variable for `postedFiles` but we should
186
+ // use the CacheAPI because, technically speaking, the SW could be disposed
187
+ // and respawned in between the POST and the GET request. In practice, however,
188
+ // SWs are disposed only after 30s seconds of idleness. The POST->GET requests
189
+ // happen back-to-back..
190
+ async function handleOpenTraceRequest(req) {
191
+ const url = new URL(req.url);
192
+ console.assert(url.pathname.startsWith(OPEN_TRACE_PREFIX));
193
+ const fileKey = url.pathname.substring(OPEN_TRACE_PREFIX.length);
194
+ if (req.method === 'POST') {
195
+ const formData = await req.formData();
196
+ const qsParams = new URLSearchParams();
197
+ // Iterate over the POST fields and copy them over the querystring in
198
+ // the hash, with the exception of the trace file. The trace file is
199
+ // kept in the serviceworker and passed as a url= argument.
200
+ formData.forEach((value, key) => {
201
+ if (key === 'trace') {
202
+ if (value instanceof File) {
203
+ postedFiles.set(fileKey, value);
204
+ qsParams.set('url', req.url);
205
+ }
206
+ return;
207
+ }
208
+ qsParams.set(key, `${value}`);
209
+ }); // formData.forEach()
210
+ return Response.redirect(`${url.protocol}//${url.host}/#!/?${qsParams}`);
211
+ }
212
+ // else... method == 'GET'
213
+ const file = postedFiles.get(fileKey);
214
+ if (file !== undefined) {
215
+ postedFiles.delete(fileKey);
216
+ return new Response(file);
217
+ }
218
+ // The file /_open_trace/NNNN does not exist.
219
+ return Response.error();
220
+ }
221
+ async function installAppVersionIntoCache(version) {
222
+ const manifestUrl = `${version}/manifest.json`;
223
+ try {
224
+ console.log(LOG_TAG + `Starting installation of ${manifestUrl}`);
225
+ await caches.delete(CACHE_NAME);
226
+ const resp = await fetchWithTimeout(manifestUrl, INSTALL_TIMEOUT_MS);
227
+ const manifest = await resp.json();
228
+ const manifestResources = manifest['resources'];
229
+ if (!manifestResources || !(manifestResources instanceof Object)) {
230
+ throw new Error(`Invalid manifest ${manifestUrl} : ${manifest}`);
231
+ }
232
+ const cache = await caches.open(CACHE_NAME);
233
+ const urlsToCache = [];
234
+ // We use cache:reload to make sure that the index is always current and we
235
+ // don't end up in some cycle where we keep re-caching the index coming from
236
+ // the service worker itself.
237
+ urlsToCache.push(new Request('/', { cache: 'reload', mode: 'same-origin' }));
238
+ for (const [resource, integrity] of Object.entries(manifestResources)) {
239
+ // We use cache: no-cache rather then reload here because the versioned
240
+ // sub-resources are expected to be immutable and should never be
241
+ // ambiguous. A revalidation request is enough.
242
+ const reqOpts = {
243
+ cache: 'no-cache',
244
+ mode: 'same-origin',
245
+ integrity: `${integrity}`,
246
+ };
247
+ urlsToCache.push(new Request(`${version}/${resource}`, reqOpts));
248
+ }
249
+ await cache.addAll(urlsToCache);
250
+ console.log(LOG_TAG + 'installation completed for ' + version);
251
+ }
252
+ catch (err) {
253
+ console.error(LOG_TAG + `Installation failed for ${manifestUrl}`, err);
254
+ await caches.delete(CACHE_NAME);
255
+ throw err;
256
+ }
257
+ }
258
+ function fetchWithTimeout(req, timeoutMs) {
259
+ const url = req.url || `${req}`;
260
+ return new Promise((resolve, reject) => {
261
+ const timerId = setTimeout(() => {
262
+ reject(new Error(`Timed out while fetching ${url}`));
263
+ }, timeoutMs);
264
+ fetch(req).then((resp) => {
265
+ clearTimeout(timerId);
266
+ if (resp.ok) {
267
+ resolve(resp);
268
+ }
269
+ else {
270
+ reject(new Error(`Fetch failed for ${url}: ${resp.status} ${resp.statusText}`));
271
+ }
272
+ }, reject);
273
+ });
274
+ }
275
+
276
+ return service_worker;
277
+
278
+ })();
279
+ //# sourceMappingURL=service_worker.js.map