-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmp_profiler.js
154 lines (145 loc) · 6.01 KB
/
smp_profiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
//19/12/23
include('helpers\\callbacks_xxx.js');
include('main\\profiler\\smp_profiler_helper.js');
/* global setProfilesPath:readable, smpProfiler:readable, skipProfiles:readable */
include(fb.ComponentPath + 'docs\\Flags.js');
/* global DT_VCENTER:readable, DT_CENTER:readable, DT_END_ELLIPSIS:readable, DT_CALCRECT:readable, DT_NOPREFIX:readable, popup:readable */
if (!window.ScriptInfo.PackageId) { window.DefineScript('Profiler-SMP', { author: 'XXX', version: '1.0.0' }); }
// Default settings for all tests and memory for Foobar2000 ones
const settings = {
path: window.GetProperty('Profiles path'),
font: gdi.Font('Segoe UI', 35),
options: JSON.parse(JSON.stringify(
[
'array concatenation', 'array copying',
'array sorting', 'loops', 'comparison operators',
'comparison statements', '(de-)composition',
'guards', 'map:access', 'map:creation',
'object iteration', 'recursion', 'split'
].map((profile) => { return { profiles: [profile], memory: false, type: 'table' }; })
.concat([
{ profiles: ['tags:retrieval:info'], memory: true, type: 'table' },
{ profiles: ['tags:retrieval:tf'], memory: true, type: 'table' }
])
))
};
const defaultOptions = JSON.stringify(settings.options);
settings.options = JSON.parse(window.GetProperty('Test options', JSON.stringify(settings.options)));
if (!settings.path) {
setTimeout(() => {
settings.path = setProfilesPath();
if (settings.path) {
window.SetProperty('Profiles path', settings.path);
window.Repaint();
smpProfiler.loadProfiles(settings.path, skipProfiles);
}
}, 100);
} else { smpProfiler.loadProfiles(settings.path, skipProfiles); }
// UI
addEventListener('on_paint', (gr) => {
const w = window.Width / 2;
const h = window.Height;
const center = DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX;
gr.FillSolidRect(0, 0, w, h, 0xFFF0F8FF); // AliceBlue
gr.FillSolidRect(w, 0, w * 2, h, 0xFFFFF8DC); // Cornsilk
gr.FillSolidRect(w, h / 2, w * 2, h / 2, 0xFFDDA0DD); // Plum
gr.FillSolidRect(w * 3 / 2, h / 2, w * 2, h / 2, 0xFFBC8F8F); // RosyBrown
gr.GdiDrawText(
smpProfiler.progress !== null
? smpProfiler.progress + '%'
: 'Run' + (!settings.path ? '\n(set profiles path first)' : ''), settings.font, 0xFF000000, 0, 0, w, h, center
);
gr.GdiDrawText('Profiles path', settings.font, 0xFF000000, w, 0, w, h / 2, center);
gr.GdiDrawText('Test Settings', settings.font, 0xFF000000, w, h / 2, w / 2, h / 2, center);
gr.GdiDrawText('Reset Settings', settings.font, 0xFF000000, w * 3 / 2, h / 2, w / 2, h / 2, center);
});
// Buttons
addEventListener('on_mouse_lbtn_up', (x, y, mask) => { // eslint-disable-line no-unused-vars
const w = window.Width / 2;
const h = window.Height;
if (x <= w) {
if (!settings.path || !utils.IsDirectory(settings.path)) {
on_mouse_lbtn_up(w + 1, 0);
} else {
// Retrieve default settings to also inform the user about inherited ones
smpProfiler.reportSettings(settings.options);
const WshShellUI = new ActiveXObject('WScript.Shell');
const answer = WshShellUI.Popup('Tests will be run during some minutes.\nWindow will appear to be blocked.\nCheck popup for full list, do you want to continue?', 0, window.ScriptInfo.Name, popup.question + popup.yes_no);
if (answer === popup.yes) {
settings.options.forEach((opt) => { smpProfiler.runAndReport(opt); });
}
}
} else if (y >= h / 2) {
if (x >= w * 3 / 2) {
const WshShellUI = new ActiveXObject('WScript.Shell');
const answer = WshShellUI.Popup('Restore default tests?\n(Profiles path will not be changed)', 0, window.ScriptInfo.Name, popup.question + popup.yes_no);
if (answer === popup.yes) {
settings.options = JSON.parse(defaultOptions);
window.SetProperty('Test options', JSON.stringify(settings.options));
}
} else {
let input = {};
try {
input = JSON.parse(utils.InputBox(window.ID, 'Edit options:\n(multiple tests may be added to the array)', 'SMP Profiler', JSON.stringify(settings.options), true));
settings.options = input;
window.SetProperty('Test options', JSON.stringify(settings.options));
} catch (e) {
if (e.message.indexOf('Dialog window was closed') === -1) {
fb.ShowPopupMessage(e, 'JSON error');
}
}
}
} else {
const input = setProfilesPath();
if (input) {
smpProfiler.loadProfiles(input, smpProfiler.loadProfiles(settings.path, skipProfiles));
settings.path = input;
window.SetProperty('Profiles path', settings.path);
window.Repaint();
}
}
});
// Tooltip
window.Tooltip.SetMaxWidth(500);
window.Tooltip.time = Date.now();
window.Tooltip.lastX = 0;
window.Tooltip.lastY = 0;
addEventListener('on_mouse_move', (x, y) => {
const w = window.Width / 2;
const h = window.Height;
let text = '';
if (x <= w) {
text += smpProfiler.progress !== null
? smpProfiler.progress + '%'
: 'Run:' + (!settings.path ? '\n(set profiles path first)' : '');
text += '\n--------------------------------------------------------------------------------------------------' +
'\nTotal tests: ' + settings.options.length +
'\nProfiles: ' + settings.options.map((o) => o.profiles.join(', ')).join(', ');
} else if (y >= h / 2) {
if (x >= w * 3 / 2) { text += 'Reset Settings'; }
else { text = 'Test Settings'; }
} else {
text += 'Profiles path:';
text += '\n--------------------------------------------------------------------------------------------------' +
'\n' + settings.path;
}
if (text !== window.Tooltip.Text) { window.Tooltip.Text = text; window.Tooltip.Activate(); }
setTimeout(() => { // Update tooltip without flickering
const time = Date.now() - window.Tooltip.time;
if (time > 250 && (Math.abs(window.Tooltip.lastX - x) >= 10 || Math.abs(window.Tooltip.lastY - y) >= 10)) {
window.Tooltip.time = Date.now();
window.Tooltip.TrackPosition(x, y);
window.Tooltip.lastX = x;
window.Tooltip.lastY = y;
window.Tooltip.TrackActivate = true;
}
}, 100);
});
addEventListener('on_mouse_leave', () => {
window.Tooltip.Text = '';
window.Tooltip.Deactivate();
});
addEventListener('on_script_unload', () => {
window.Tooltip.Deactivate();
});