OILS / vendor / souffle / profile / htmlJsUtil.h View on Github | oilshell.org

174 lines, 6 significant
1#include <string>
2
3namespace souffle {
4namespace profile {
5namespace html {
6std::string jsUtil = R"___(
7/*
8 * Souffle - A Datalog Compiler
9 * Copyright (c) 2017, The Souffle Developers. All rights reserved
10 * Licensed under the Universal Permissive License v 1.0 as shown at:
11 * - https://opensource.org/licenses/UPL
12 * - <souffle root>/licenses/SOUFFLE-UPL.txt
13 */
14
15
16function clean_percentages(data) {
17 if (data < 1) {
18 return data.toFixed(3);
19 }
20 return data.toPrecision(3);
21}
22
23function humanise_time(time) {
24 if (precision) return time.toString();
25 if (time < 1e-9) {
26 return '0';
27 }
28 if (time < 1) {
29 milli = time * 1000.0;
30 if (milli > 1) {
31 return time.toFixed(3) + "s"
32 }
33 micro = milli * 1000.0;
34 if (micro >= 1) {
35 return micro.toFixed(1) + "µs"
36 }
37 return (micro*1000).toFixed(1) + "ns"
38 } else {
39 minutes = (time / 60.0);
40 if (minutes < 3) return time.toPrecision(3) + "s";
41 hours = (minutes / 60);
42 if (hours < 3) return minutes.toFixed(2) + "m";
43 days = (hours / 24);
44 if (days < 3) return hours.toFixed(2) + "H";
45 weeks = (days / 7);
46 if (weeks < 3) return days.toFixed(2) + "D";
47 year = (days / 365);
48 if (year < 3) return weeks.toFixed(2) + "W";
49 return year.toFixed(2) + "Y"
50 }
51}
52
53function minify_memory(value) {
54 if (value < 1024 * 10) {
55 return value + 'B';
56 } else if (value < 1024 * 1024 * 10) {
57 return Math.round(value / 1024) + 'kB';
58 } else if (value < 1024 * 1024 * 1024 * 10) {
59 return Math.round(value / (1024 * 1024)) + 'MB';
60 } else if (value < 1024 * 1024 * 1024 * 1024 * 10) {
61 return Math.round(value / Math.round(1024 * 1024 * 1024)) + 'GB';
62 } else {
63 return Math.round(value / Math.round(1024 * 1024 * 1024 * 1024)) + 'TB';
64 }
65}
66
67function minify_numbers(num) {
68 if (precision) return num.toString();
69 kilo = (num / 1000);
70 if (kilo < 1) return num;
71 mil = (kilo / 1000);
72 if (mil < 1) return kilo.toPrecision(3) + "K";
73 bil = (mil / 1000);
74 if (bil < 1) return mil.toPrecision(3) + "M";
75 tril = (bil / 1000);
76 if (tril < 1) return bil.toPrecision(3) + "B";
77 quad = (tril / 1000);
78 if (quad < 1) return tril.toPrecision(3) + "T";
79 quin = (quad / 1000);
80 if (quin < 1) return quad.toPrecision(3) + "q";
81 sex = (quin / 1000);
82 if (sex < 1) return quin.toPrecision(3) + "Q";
83 sept = (sex / 1000);
84 if (sept < 1) return sex.toPrecision(3) + "s";
85 return sept.toFixed(2) + "S"
86}
87
88
89
90(function () {
91 var cleanNumber = function (x) {
92 var num = x.slice(0, -1);
93 var spec = x.slice(-1);
94 if (spec == 'K') {
95 return parseFloat(num) * 1e3;
96 } else if (spec == 'M') {
97 return parseFloat(num) * 1e6;
98 } else if (spec == "B") {
99 return parseFloat(num) * 1e9;
100 } else if (spec == "T") {
101 return parseFloat(num) * 1e12;
102 } else if (spec == "q") {
103 return parseFloat(num) * 1e15;
104 } else if (spec == "Q") {
105 return parseFloat(num) * 1e18;
106 } else if (spec == "s") {
107 return parseFloat(num) * 1e21;
108 } else if (spec == "S") {
109 return parseFloat(num) * 1e24;
110 }
111 return parseFloat(x);
112 };
113 var a = function (a) {
114 return a;
115 }, b = function (a, b) {
116 return a = cleanNumber(a), b = cleanNumber(b), a = isNaN(a) ? 0 : a, b = isNaN(b) ? 0 : b, a - b
117 };
118 Tablesort.extend("number", function (a) {
119 return a.match(/.*/)
120 }, function (c, d) {
121 return c = a(c), d = a(d), b(d, c)
122 })
123})();
124
125(function () {
126 var compare = function (a, b) {
127 return a.localeCompare(b);
128 };
129 Tablesort.extend("text", function (a) {
130 return a.match(/.*/)
131 }, function (c, d) {
132 return compare(d, c)
133 })
134})();
135
136(function () {
137 var cleanNumber = function (x) {
138 if (x.slice(-1) == 'Y') {
139 return parseFloat(x.slice(0, -1)) * 365 * 24 * 60 * 60;
140 } else if (x.slice(-1) == 'W') {
141 return parseFloat(x.slice(0, -1)) * 7 * 24 * 60 * 60;
142 } else if (x.slice(-1) == "D") {
143 return parseFloat(x.slice(0, -1)) * 24 * 60 * 60;
144 } else if (x.slice(-1) == "H") {
145 return parseFloat(x.slice(0, -1)) * 60 * 60;
146 } else if (x.slice(-1) == "m") {
147 return parseFloat(x.slice(0, -1)) * 60;
148 } else if (x.slice(-2) == "µs") {
149 return parseFloat(x.slice(0, -2)) / 1e6;
150 } else if (x.slice(-2) == "ns") {
151 return parseFloat(x.slice(0, -2)) / 1e9;
152 } else if (x.slice(-1) == "s") {
153 return parseFloat(x.slice(0, -1));
154 }
155 return parseFloat(x);
156 },
157 compareNumber = function (a, b) {
158 a = isNaN(a) ? 0 : a;
159 b = isNaN(b) ? 0 : b;
160 return a - b;
161 };
162 Tablesort.extend('time', function (item) {
163 return true;
164 }, function (a, b) {
165 a = cleanNumber(a);
166 b = cleanNumber(b);
167 return compareNumber(b, a);
168 });
169}());
170
171)___";
172}
173} // namespace profile
174} // namespace souffle