diff --git a/import-fuchsia/src/import-fuchsia.cpp b/import-fuchsia/src/import-fuchsia.cpp index 9f3cf8f4..5487dc7f 100644 --- a/import-fuchsia/src/import-fuchsia.cpp +++ b/import-fuchsia/src/import-fuchsia.cpp @@ -85,7 +85,8 @@ struct DecodeState { // Append a string representation of `val` to `res` void appendArgumentValue(std::string &res, ArgumentValue &val) { - char buf[32]; buf[31]=0; + char buf[32]; + buf[31] = 0; if (std::holds_alternative(val)) { res += std::get(val); } else if (std::holds_alternative(val)) { @@ -270,7 +271,7 @@ void readArgument(std::vector &args, DecodeState &dec, value = i; } break; case 5: { - double i = r.p[offset]; + double i = *((double*) &r.p[offset]); offset += 1; value = i; } break; @@ -309,6 +310,24 @@ void readArguments(std::vector &args, DecodeState &dec, Record r, readArgument(args, dec, r, offset); } +bool argumentIsNumber(Argument const &arg) { + return std::holds_alternative(arg.value) || + std::holds_alternative(arg.value) || + std::holds_alternative(arg.value); +} + +double argumentToNumber(Argument const &arg) { + if (std::holds_alternative(arg.value)) { + return std::get(arg.value); + } else if (std::holds_alternative(arg.value)) { + return static_cast(std::get(arg.value)); + } else if (std::holds_alternative(arg.value)) { + return static_cast(std::get(arg.value)); + } else { + assert(false); + } +} + // text made of arguments void printArgumentsToString(std::string &res, std::vector &args) { for (auto &kv : args) { @@ -402,18 +421,65 @@ int main(int argc, char **argv) { break; } - case 4: { - // complete duration - const auto tid = getPseudoTid(dec, th); - const auto ts0 = timestamp; - const auto ts1 = r.p[offset]; // end timestamp + case 1: { + // counter + for (auto &kv : arguments) { + bool plotFound = false; + auto &metricName = kv.name; + + if (!argumentIsNumber(kv)) + continue; + + auto dataPoint = std::make_pair(timestamp, argumentToNumber(kv)); + + // The input file is assumed to have only very few metrics, + // so iterating through plots is not a problem. + for (auto &plot : plots) { + if (plot.name == metricName) { + plot.data.emplace_back(dataPoint); + plotFound = true; + break; + } + } + if (!plotFound) { + auto formatting = tracy::PlotValueFormatting::Number; + plots.emplace_back(tracy::Worker::ImportEventPlots{ + std::move(metricName), formatting, {dataPoint}}); + } + } + break; + } + + case 2: { + // duration begin std::string zoneText; printArgumentsToString(zoneText, arguments); timeline.emplace_back(tracy::Worker::ImportEventTimeline{ - tid, ts0, name, std::move(zoneText), false, std::move(locFile), - locLine}); + getPseudoTid(dec, th), timestamp, name, std::move(zoneText), false, + std::move(locFile), locLine}); + break; + } + + case 3: { + // duration end + std::string zoneText; + printArgumentsToString(zoneText, arguments); + timeline.emplace_back(tracy::Worker::ImportEventTimeline{ + getPseudoTid(dec, th), timestamp, "", std::move(zoneText), true}); + break; + } + + case 4: { + // complete duration + const auto ts_end = r.p[offset]; // end timestamp + const auto tid = getPseudoTid(dec, th); + std::string zoneText; + printArgumentsToString(zoneText, arguments); + timeline.emplace_back(tracy::Worker::ImportEventTimeline{ + tid, timestamp, name, std::move(zoneText), false, + std::move(locFile), locLine}); timeline.emplace_back( - tracy::Worker::ImportEventTimeline{tid, ts1, "", "", true}); + tracy::Worker::ImportEventTimeline{tid, ts_end, "", "", true}); break; } @@ -421,21 +487,6 @@ int main(int argc, char **argv) { } } - /* - if( type == "b" || type == "B" ) - { - timeline.emplace_back( tracy::Worker::ImportEventTimeline { - getPseudoTid(v), - uint64_t( v["ts"].get() * 1000. ), - v["name"].get(), - std::move(zoneText), - false, - std::move(locFile), - locLine - } ); - } - */ - break; } @@ -469,8 +520,8 @@ int main(int argc, char **argv) { for( auto& kv : v["args"].items() ) { const auto val = kv.value(); - const std::string s = val.is_string() ? val.get() : - val.dump(); zoneText += kv.key() + ": " + s + "\n"; + const std::string s = val.is_string() ? val.get() + : val.dump(); zoneText += kv.key() + ": " + s + "\n"; } } @@ -559,8 +610,8 @@ int main(int argc, char **argv) { // NOTE: With C++20 one could say metricName.ends_with( "_bytes" ) instead of rfind auto metricNameLen = metricName.size(); if ( - metricNameLen >= 6 && metricName.rfind( "_bytes" ) == metricNameLen - 6 ) { - formatting = tracy::PlotValueFormatting::Memory; + metricNameLen >= 6 && metricName.rfind( "_bytes" ) == metricNameLen - 6 ) + { formatting = tracy::PlotValueFormatting::Memory; } plots.emplace_back( tracy::Worker::ImportEventPlots {