Added duration in profiler output

pull/219/head
yhirose 2 years ago
parent 5a83950514
commit 5f94f584dc
  1. 1
      docs/index.html
  2. 62
      docs/index.js
  3. 2
      docs/native.js
  4. BIN
      docs/native.wasm
  5. 9
      docs/style.css
  6. 18
      peglib.h

@ -39,6 +39,7 @@
<div id="code-info" class="editor-info"></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/jquery/3.3.1/jquery.min.js"></script>
<script src="index.js"></script>

@ -72,7 +72,6 @@ function parse() {
const optimazationMode = $('#opt-mode').val();
const packrat = $('#packrat').prop('checked');
const autoRefresh = $('#auto-refresh').prop('checked');
$grammarInfo.html('');
$grammarValidation.hide();
@ -87,33 +86,46 @@ function parse() {
}
const mode = optimazationMode == 'all';
const data = JSON.parse(Module.lint(grammarText, codeText, mode, packrat));
if (data.grammar_valid) {
$grammarValidation.removeClass('validation-invalid').show();
codeAst.insert(data.ast);
codeAstOptimized.insert(data.astOptimized);
codeProfile.insert(data.profile);
if (data.source_valid) {
$codeValidation.removeClass('validation-invalid').show();
$('#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));
$('#overlay').css({
'z-index': '-1',
'display': 'none',
'background-color': 'rgba(1, 1, 1, 1.0)'
});
if (data.grammar_valid) {
$grammarValidation.removeClass('validation-invalid').show();
codeAst.insert(data.ast);
codeAstOptimized.insert(data.astOptimized);
codeProfile.insert(data.profile);
if (data.source_valid) {
$codeValidation.removeClass('validation-invalid').show();
} else {
$codeValidation.addClass('validation-invalid').show();
}
if (data.code.length > 0) {
const html = generateErrorListHTML(data.code);
$codeInfo.html(html);
}
} else {
$codeValidation.addClass('validation-invalid').show();
$grammarValidation.addClass('validation-invalid').show();
}
if (data.code.length > 0) {
const html = generateErrorListHTML(data.code);
$codeInfo.html(html);
if (data.grammar.length > 0) {
const html = generateErrorListHTML(data.grammar);
$grammarInfo.html(html);
}
} else {
$grammarValidation.addClass('validation-invalid').show();
}
if (data.grammar.length > 0) {
const html = generateErrorListHTML(data.grammar);
$grammarInfo.html(html);
}
}, 0);
}
// Event handing for text editiing
@ -190,6 +202,8 @@ $('#main').css({
var Module = {
onRuntimeInitialized: function() {
// Initial parse
parse();
if ($('#auto-refresh').prop('checked')) {
parse();
}
}
};

File diff suppressed because one or more lines are too long

Binary file not shown.

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

@ -4563,6 +4563,7 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
std::vector<Item> items;
std::map<std::string, size_t> index;
size_t total = 0;
std::chrono::steady_clock::time_point start;
};
parser.enable_trace(
@ -4593,8 +4594,14 @@ inline void enable_profiling(parser &parser, std::ostream &os) {
}
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_fail = 0;
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", "", "", "",
total_success * 100.0 / grand_total,
total_fail * 100.0 / grand_total, "% success/fail");
os << buff << std::endl;
os << buff << std::endl << std::endl;
;
size_t id = 0;
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 stats = std::any_cast<Stats *>(trace_data);
delete stats;

Loading…
Cancel
Save