Added duration in profiler output

This commit is contained in:
yhirose 2022-06-10 20:19:48 -04:00
parent 5a83950514
commit 5f94f584dc
6 changed files with 62 additions and 26 deletions

View File

@ -39,6 +39,7 @@
<div id="code-info" class="editor-info"></div> <div id="code-info" class="editor-info"></div>
</div> </div>
</div> </div>
<div id="overlay"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="index.js"></script> <script src="index.js"></script>

View File

@ -72,7 +72,6 @@ function parse() {
const optimazationMode = $('#opt-mode').val(); const optimazationMode = $('#opt-mode').val();
const packrat = $('#packrat').prop('checked'); const packrat = $('#packrat').prop('checked');
const autoRefresh = $('#auto-refresh').prop('checked');
$grammarInfo.html(''); $grammarInfo.html('');
$grammarValidation.hide(); $grammarValidation.hide();
@ -87,7 +86,19 @@ function parse() {
} }
const mode = optimazationMode == 'all'; const mode = optimazationMode == 'all';
$('#overlay').css({
'z-index': '1',
'display': 'block',
'background-color': 'rgba(0, 0, 0, 0.1)'
});
window.setTimeout(() => {
const data = JSON.parse(Module.lint(grammarText, codeText, mode, packrat)); const data = JSON.parse(Module.lint(grammarText, codeText, mode, packrat));
$('#overlay').css({
'z-index': '-1',
'display': 'none',
'background-color': 'rgba(1, 1, 1, 1.0)'
});
if (data.grammar_valid) { if (data.grammar_valid) {
$grammarValidation.removeClass('validation-invalid').show(); $grammarValidation.removeClass('validation-invalid').show();
@ -114,6 +125,7 @@ function parse() {
const html = generateErrorListHTML(data.grammar); const html = generateErrorListHTML(data.grammar);
$grammarInfo.html(html); $grammarInfo.html(html);
} }
}, 0);
} }
// Event handing for text editiing // Event handing for text editiing
@ -190,6 +202,8 @@ $('#main').css({
var Module = { var Module = {
onRuntimeInitialized: function() { onRuntimeInitialized: function() {
// Initial parse // Initial parse
if ($('#auto-refresh').prop('checked')) {
parse(); parse();
} }
}
}; };

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -13,6 +13,7 @@ body {
#main { #main {
flex: 1; flex: 1;
display: none; display: none;
z-index: 0;
} }
.editor-container { .editor-container {
flex: 1; flex: 1;
@ -90,3 +91,11 @@ body {
.show-toggle { .show-toggle {
margin-right: 6px; margin-right: 6px;
} }
#overlay {
position: absolute;
width: 100vw;
height: 100vh;
cursor: wait;
display: none;
z-index: -1;
}

View File

@ -4563,6 +4563,7 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
std::vector<Item> items; std::vector<Item> items;
std::map<std::string, size_t> index; std::map<std::string, size_t> index;
size_t total = 0; size_t total = 0;
std::chrono::steady_clock::time_point start;
}; };
parser.enable_trace( parser.enable_trace(
@ -4593,8 +4594,14 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
} }
if (index == 0) { if (index == 0) {
char buff[BUFSIZ]; auto end = std::chrono::steady_clock::now();
auto µs = std::chrono::duration_cast<std::chrono::microseconds>(
end - stats.start)
.count();
auto s = µs / 1000000.0;
os << "duration: " << s << "s (" << µs << "µs)" << std::endl << std::endl;
char buff[BUFSIZ];
size_t total_success = 0; size_t total_success = 0;
size_t total_fail = 0; size_t total_fail = 0;
for (auto &[name, success, fail] : stats.items) { for (auto &[name, success, fail] : stats.items) {
@ -4614,7 +4621,8 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
sprintf(buff, "%4s %10s %5s %10.2f %10.2f %s", "", "", "", sprintf(buff, "%4s %10s %5s %10.2f %10.2f %s", "", "", "",
total_success * 100.0 / grand_total, total_success * 100.0 / grand_total,
total_fail * 100.0 / grand_total, "% success/fail"); total_fail * 100.0 / grand_total, "% success/fail");
os << buff << std::endl; os << buff << std::endl << std::endl;
;
size_t id = 0; size_t id = 0;
for (auto &[name, success, fail] : stats.items) { for (auto &[name, success, fail] : stats.items) {
@ -4628,7 +4636,11 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
} }
} }
}, },
[&](auto &trace_data) { trace_data = new Stats{}; }, [&](auto &trace_data) {
auto stats = new Stats{};
stats->start = std::chrono::steady_clock::now();
trace_data = stats;
},
[&](auto &trace_data) { [&](auto &trace_data) {
auto stats = std::any_cast<Stats *>(trace_data); auto stats = std::any_cast<Stats *>(trace_data);
delete stats; delete stats;