mirror of
https://github.com/peridotbuild/peridot.git
synced 2024-11-05 05:11:24 +00:00
6 lines
3.9 KiB
Go
Executable File
6 lines
3.9 KiB
Go
Executable File
// Generated by go_embed_data for //internal/ibazel/profiler:js. DO NOT EDIT.
|
|
|
|
package profiler
|
|
|
|
var js = []byte("// Copyright 2017 The Bazel Authors. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n(function(){\n function extractUrl() {\n return [...window.document.getElementsByTagName('script') ]\n .filter(function(e) { return e.src; })\n .map(function(e) {\n const a = document.createElement('a');\n a.href = e.src;\n return a;\n })\n .filter(function (a) { return a.pathname == \"/profiler.js\"; })\n .map(function (a) { return `${a.protocol}//${a.host}/profiler-event`; })\n .reduce(function(acc, u) { return acc || u; });\n };\n\n const profilerEventUrl = extractUrl();\n if (!profilerEventUrl) {\n this.console.error(\"iBazel profiler disabled because it could not find its own <SCRIPT> tag\");\n return;\n }\n\n if (!window.navigator.sendBeacon) {\n console.error(\n \"iBazel profiler disabled because Beacon API is not available\")\n return;\n }\n\n function profilerEvent(eventType, eventData) {\n if (!eventType || typeof eventType != 'string') {\n console.error(\"Invalid iBazel profiler event type\", eventType);\n return;\n }\n if (typeof eventData == 'object') {\n eventData = JSON.stringify(eventData)\n }\n const event = { type: eventType, time: Date.now() };\n event.timeSinceNavigationStart = event.time - window.performance.timing.navigationStart;\n if (eventData) {\n event.data = eventData.toString();\n }\n const data = JSON.stringify(event)\n if (!window.navigator.sendBeacon(profilerEventUrl, data)) {\n console.error(\"Failed to send profile data to \", profilerEventUrl);\n }\n }\n\n // Expose a public window.IBazelProfileEvent API for the user space to be\n // able to send profile events\n window.IBazelProfileEvent = profilerEvent;\n\n window.addEventListener(\"load\", function() {\n let timing = window.performance.timing;\n\n profilerEvent(\"PAGE_LOAD\", {\n // deltas\n pageLoadTime: timing.loadEventStart - timing.navigationStart, // loadEventEnd is not set yet\n fetchTime: timing.responseEnd - timing.fetchStart,\n connectTime: timing.connectEnd - timing.connectStart,\n requestTime: timing.responseEnd - timing.requestStart,\n responseTime: timing.responseEnd - timing.responseStart,\n renderTime: timing.domComplete - timing.domLoading,\n\n // absolutes\n navigationStart: timing.navigationStart,\n unloadEventStart: timing.unloadEventStart,\n unloadEventEnd: timing.unloadEventEnd,\n redirectStart: timing.redirectStart,\n redirectEnd: timing.redirectEnd,\n fetchStart: timing.fetchStart,\n domainLookupStart: timing.domainLookupStart,\n domainLookupEnd: timing.domainLookupEnd,\n connectStart: timing.connectStart,\n connectEnd: timing.connectEnd,\n secureConnectionStart: timing.secureConnectionStart,\n requestStart: timing.requestStart,\n responseStart: timing.responseStart,\n responseEnd: timing.responseEnd,\n domLoading: timing.domLoading,\n domInteractive: timing.domInteractive,\n domContentLoadedEventStart: timing.domContentLoadedEventStart,\n domContentLoadedEventEnd: timing.domContentLoadedEventEnd,\n domComplete: timing.domComplete,\n loadEventStart: timing.loadEventStart,\n });\n }, false);\n})();")
|