|
| 1 | +/* |
| 2 | + * Jawk |
| 3 | + * Copyright (C) 2006 - 2026 MetricsHub |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as |
| 7 | + * published by the Free Software Foundation, either version 3 of the |
| 8 | + * License, or (at your option) any later version. |
| 9 | + */ |
| 10 | +(function() { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + function installBenchmarkSupport(angular) { |
| 14 | + var siteModule = angular.module('sentry.site'); |
| 15 | + var host = document.getElementById('benchmark-application'); |
| 16 | + if (host) { |
| 17 | + host.innerHTML = '<jawk-benchmark-report></jawk-benchmark-report>'; |
| 18 | + } |
| 19 | + |
| 20 | + siteModule.component('jawkBenchmarkReport', { |
| 21 | + controller: ['$http', BenchmarkController], |
| 22 | + controllerAs: '$ctrl', |
| 23 | + templateUrl: 'templates/benchmarks.html' |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + function BenchmarkController($http) { |
| 28 | + var $ctrl = this; |
| 29 | + var indexUrl = 'benchmarks/index.json'; |
| 30 | + |
| 31 | + $ctrl.loading = true; |
| 32 | + $ctrl.releaseLoading = false; |
| 33 | + $ctrl.error = null; |
| 34 | + $ctrl.releaseError = null; |
| 35 | + $ctrl.releases = []; |
| 36 | + $ctrl.results = []; |
| 37 | + $ctrl.environment = null; |
| 38 | + |
| 39 | + $ctrl.metric = function(result) { |
| 40 | + return result.primaryMetric || {}; |
| 41 | + }; |
| 42 | + |
| 43 | + $ctrl.shortBenchmarkName = function(benchmark) { |
| 44 | + var marker = 'JRTCompare2Benchmark.'; |
| 45 | + var index; |
| 46 | + if (!benchmark) { |
| 47 | + return ''; |
| 48 | + } |
| 49 | + index = benchmark.indexOf(marker); |
| 50 | + return index >= 0 ? benchmark.substring(index + marker.length) : benchmark; |
| 51 | + }; |
| 52 | + |
| 53 | + $ctrl.forkCount = function(result) { |
| 54 | + var metric = $ctrl.metric(result); |
| 55 | + return metric.rawData ? metric.rawData.length : ''; |
| 56 | + }; |
| 57 | + |
| 58 | + $ctrl.releaseKey = function(release) { |
| 59 | + return release.versionPath || release.version; |
| 60 | + }; |
| 61 | + |
| 62 | + $ctrl.releaseLabel = function(release) { |
| 63 | + if (!release) { |
| 64 | + return ''; |
| 65 | + } |
| 66 | + return release.date ? release.version + ' (' + release.date + ')' : release.version; |
| 67 | + }; |
| 68 | + |
| 69 | + $ctrl.runnerLabel = function(environment) { |
| 70 | + if (!environment || !environment.runner) { |
| 71 | + return ''; |
| 72 | + } |
| 73 | + return [environment.runner.os, environment.runner.arch, environment.runner.name].filter(Boolean).join(' / '); |
| 74 | + }; |
| 75 | + |
| 76 | + $ctrl.systemLabel = function(environment) { |
| 77 | + var label; |
| 78 | + var system; |
| 79 | + if (!environment || !environment.system) { |
| 80 | + return ''; |
| 81 | + } |
| 82 | + system = environment.system; |
| 83 | + label = [system.platform, system.release, system.arch].filter(Boolean).join(' / '); |
| 84 | + if (system.cpuCount) { |
| 85 | + label += ' / ' + system.cpuCount + ' CPUs'; |
| 86 | + } |
| 87 | + if (system.cpus && system.cpus.length) { |
| 88 | + label += ' / ' + system.cpus.join(', '); |
| 89 | + } |
| 90 | + return label; |
| 91 | + }; |
| 92 | + |
| 93 | + $ctrl.loadRelease = function(release) { |
| 94 | + if (!release) { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + $ctrl.releaseLoading = true; |
| 99 | + $ctrl.releaseError = null; |
| 100 | + $ctrl.results = []; |
| 101 | + $ctrl.environment = null; |
| 102 | + |
| 103 | + $http.get(release.jmh, { cache: false }).then(function(response) { |
| 104 | + $ctrl.results = response.data || []; |
| 105 | + $ctrl.results.sort(function(left, right) { |
| 106 | + return left.benchmark.localeCompare(right.benchmark); |
| 107 | + }); |
| 108 | + }, function() { |
| 109 | + $ctrl.releaseError = 'Benchmark results could not be loaded for ' + release.version + '.'; |
| 110 | + }).finally(function() { |
| 111 | + $ctrl.releaseLoading = false; |
| 112 | + }); |
| 113 | + |
| 114 | + if (release.environment) { |
| 115 | + $http.get(release.environment, { cache: false }).then(function(response) { |
| 116 | + $ctrl.environment = response.data; |
| 117 | + }); |
| 118 | + } |
| 119 | + }; |
| 120 | + |
| 121 | + $http.get(indexUrl, { cache: false }).then(function(response) { |
| 122 | + var data = response.data || {}; |
| 123 | + var latest = data.latest; |
| 124 | + var releases = data.releases || []; |
| 125 | + var selected = releases.length ? releases[0] : null; |
| 126 | + var index; |
| 127 | + |
| 128 | + $ctrl.releases = releases; |
| 129 | + for (index = 0; index < releases.length; index++) { |
| 130 | + if (releases[index].version === latest) { |
| 131 | + selected = releases[index]; |
| 132 | + break; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + if (!selected) { |
| 137 | + $ctrl.error = 'No published benchmark releases were found in ' + indexUrl + '.'; |
| 138 | + return; |
| 139 | + } |
| 140 | + |
| 141 | + $ctrl.selectedRelease = selected; |
| 142 | + $ctrl.loadRelease(selected); |
| 143 | + }, function() { |
| 144 | + $ctrl.error = 'No benchmark index is published yet. Release benchmarks will create ' + indexUrl + '.'; |
| 145 | + }).finally(function() { |
| 146 | + $ctrl.loading = false; |
| 147 | + }); |
| 148 | + } |
| 149 | + |
| 150 | + function showAngularMissing() { |
| 151 | + var host = document.getElementById('benchmark-application'); |
| 152 | + if (host) { |
| 153 | + host.innerHTML = '<div class="alert alert-warning">AngularJS is not available, so benchmark results cannot be loaded dynamically.</div>'; |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + function installWhenReady() { |
| 158 | + if (!window.angular) { |
| 159 | + showAngularMissing(); |
| 160 | + return; |
| 161 | + } |
| 162 | + installBenchmarkSupport(window.angular); |
| 163 | + } |
| 164 | + |
| 165 | + document.addEventListener('DOMContentLoaded', installWhenReady); |
| 166 | +}()); |
0 commit comments