From 7935e5055bc2c3ae17278bf55f6114f022dc4f15 Mon Sep 17 00:00:00 2001 From: sbekele Date: Thu, 13 Jun 2024 03:13:39 +0000 Subject: [PATCH] timeline cleanup --- xprof/btx_timeline.cpp | 156 +++++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/xprof/btx_timeline.cpp b/xprof/btx_timeline.cpp index 3ea7397e..8681a5ed 100644 --- a/xprof/btx_timeline.cpp +++ b/xprof/btx_timeline.cpp @@ -5,16 +5,11 @@ #include // set precision #include // stdcout #include -//#include #include #include #include #include // pair -#include -#include - - #include "perfetto_prunned.pb.h" #define TRUSTED_PACKED_SEQUENCE_ID 10 @@ -43,8 +38,16 @@ struct timeline_dispatch_s { std::unordered_map hp_dfsdev2fptracks; perfetto_pruned::Trace trace; }; + +struct FabricDetails { + uintptr_t hFabricPort; + bool RxTx; + uint32_t fabricId; + uint32_t remotePortId; +}; + using timeline_dispatch_t = struct timeline_dispatch_s; -using uuid_getter_t = perfetto_uuid_t (*)(timeline_dispatch_t *, const std::string &, uint64_t, uintptr_t, std::optional, uint32_t, std::optional); +using uuid_getter_t = perfetto_uuid_t (*)(timeline_dispatch_t *, const std::string &, uint64_t, uintptr_t, uint32_t, std::optional); static perfetto_uuid_t gen_perfetto_uuid() { // Start at one, Look like UUID 0 is special @@ -83,34 +86,35 @@ static perfetto_uuid_t get_parent_counter_track_uuid(timeline_dispatch_t *dispat return hp_uuid; } -static perfetto_uuid_t -get_counter_track_uuuid(timeline_dispatch_t *dispatch, - std::unordered_map &counter_tracks, - const std::string &track_name, const std::string &hostname, uint64_t process_id, - thapi_device_id did, thapi_domain_idx domain, int64_t unit_multiplier = 1, - std::optional hFabricPort = std::nullopt, - std::unordered_map *counter_tracks_fp = nullptr, std::optional RxTx = std::nullopt) { +static perfetto_uuid_t get_counter_track_uuuid(timeline_dispatch_t *dispatch, + std::unordered_map &counter_tracks, + const std::string &track_name, const std::string &hostname, uint64_t process_id, + thapi_device_id did, thapi_domain_idx domain, int64_t unit_multiplier = 1, + std::optional details = std::nullopt, + std::unordered_map *counter_tracks_fp = nullptr) { perfetto_uuid_t hp_dev_uuid = 0; perfetto_uuid_t hp_uuid; - if (hFabricPort.has_value() && counter_tracks_fp != nullptr && RxTx.has_value()) { - auto [it, inserted] = counter_tracks_fp->insert({{hostname, process_id, did, hFabricPort.value(), domain, RxTx.value()}, hp_dev_uuid}); + + if (details && counter_tracks_fp != nullptr) { // Corrected variable name 'options' to 'option' + auto [it, inserted] = counter_tracks_fp->insert({{hostname, process_id, did, details->hFabricPort, domain, details->RxTx}, + hp_dev_uuid}); auto &potential_uuid = it->second; - if (!inserted) + if (!inserted) return potential_uuid; hp_uuid = get_parent_counter_track_uuid(dispatch, hostname, process_id, did); hp_dev_uuid = gen_perfetto_uuid(); potential_uuid = hp_dev_uuid; - } else { - auto [it, inserted] = counter_tracks.insert({{hostname, process_id, did, domain}, hp_dev_uuid}); - auto &potential_uuid = it->second; - if (!inserted) - return potential_uuid; - - hp_uuid = get_parent_counter_track_uuid(dispatch, hostname, process_id, did); - hp_dev_uuid = gen_perfetto_uuid(); - potential_uuid = hp_dev_uuid; - } + } else { + auto [it, inserted] = counter_tracks.insert({{hostname, process_id, did, domain}, hp_dev_uuid}); + auto &potential_uuid = it->second; + if (!inserted) + return potential_uuid; + + hp_uuid = get_parent_counter_track_uuid(dispatch, hostname, process_id, did); + hp_dev_uuid = gen_perfetto_uuid(); + potential_uuid = hp_dev_uuid; + } auto *packet = dispatch->trace.add_packet(); packet->set_timestamp(0); @@ -119,9 +123,11 @@ get_counter_track_uuuid(timeline_dispatch_t *dispatch, track_descriptor->set_uuid(hp_dev_uuid); track_descriptor->set_parent_uuid(hp_uuid); std::ostringstream oss; - oss << track_name << " | Domain " << domain; - if (RxTx.has_value()) { - oss << (RxTx.value() ? " TX" : " RX"); + if (details) { + oss << track_name << " | SD " << domain; + oss << " | " << details->fabricId << "<->"<< details->remotePortId << " | " <<(details->RxTx ? " TX" : " RX"); + } else { + oss << track_name << " | Domain " << domain; } track_descriptor->set_name(oss.str()); auto *counter_descriptor = track_descriptor->mutable_counter(); @@ -130,92 +136,90 @@ get_counter_track_uuuid(timeline_dispatch_t *dispatch, } static perfetto_uuid_t get_copyEU_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uintptr_t did, std::optional hFabricPort, uint32_t subDevice, - std::optional RxTx = std::nullopt) { - return get_counter_track_uuuid(dispatch, dispatch->hp_dsdev2cpytracks, "CopyEngine (%)", hostname, - process_id, did, subDevice, 100, std::nullopt, nullptr, RxTx); + uintptr_t did, uint32_t subDevice, std::optional options) { + return get_counter_track_uuuid(dispatch, dispatch->hp_dsdev2cpytracks, "CopyEngine (%)", hostname, process_id, did, subDevice, 100); } -static perfetto_uuid_t get_fpThroughput_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uintptr_t did, std::optional hFabricPort, uint32_t subDevice, std::optional RxTx) { - return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2pwrtracks, "Fabric | Throughput", hostname, - process_id, did, subDevice, 100, hFabricPort, &dispatch->hp_dfsdev2fptracks, RxTx); +static perfetto_uuid_t get_fpThroughput_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, + uintptr_t did, uint32_t subDevice, std::optional options) { + return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2pwrtracks, "FabricT", hostname, process_id, did, subDevice, 100, options, &dispatch->hp_dfsdev2fptracks); } -static perfetto_uuid_t get_power_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uintptr_t did, std::optional hFabricPort, uint32_t subDevice, std::optional RxTx) { - return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2pwrtracks, " Power", hostname, - process_id, did, subDevice, 100, std::nullopt, nullptr, RxTx); +static perfetto_uuid_t get_power_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, + uintptr_t did, uint32_t subDevice, std::optional options) { + // Extra space to maintain track sequence in the timeline + return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2pwrtracks, " Power", hostname, process_id, did, subDevice, 100); } static perfetto_uuid_t get_frequency_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uintptr_t did, std::optional hFabricPort, uint32_t subDevice, std::optional RxTx) { - return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2frqtracks, " Ferquency", hostname, - process_id, did, subDevice, 100, std::nullopt, nullptr, RxTx); + uintptr_t did, uint32_t subDevice, std::optional options) { + return get_counter_track_uuuid(dispatch, dispatch->hp_ddomain2frqtracks, " Ferquency", hostname, process_id, did, subDevice, 100); } static perfetto_uuid_t get_computeEU_track_uuuid(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uintptr_t did, std::optional hFabricPort, uint32_t subDevice, std::optional RxTx) { - return get_counter_track_uuuid(dispatch, dispatch->hp_dsdev2cpetracks, "ComputeEngine (%)", hostname, - process_id, did, subDevice, 100, std::nullopt, nullptr, RxTx); + uintptr_t did, uint32_t subDevice, std::optional options ) { + return get_counter_track_uuuid(dispatch, dispatch->hp_dsdev2cpetracks, "ComputeEngine (%)", hostname, process_id, did, subDevice, 100); } static void add_event_DTelemetry(timeline_dispatch_t *dispatch, const std::string &hostname, uint64_t process_id, - uint64_t thread_id, uintptr_t did, std::optional hFabricPort, uint32_t subDevice, - uint64_t timestamp, float value, uuid_getter_t uuid_getter, const std::string &eventName, - std::optional RxTx = std::nullopt) { + uint64_t thread_id, uintptr_t did, uint32_t subDevice, + uint64_t timestamp, float value, uuid_getter_t uuid_getter, const std::string &eventName, + std::optional options = std::nullopt) { perfetto_uuid_t track_uuid; - if (hFabricPort.has_value()) { - track_uuid = uuid_getter(dispatch, hostname, process_id, did, hFabricPort, subDevice, RxTx); - } else { - track_uuid = uuid_getter(dispatch, hostname, process_id, did, std::nullopt, subDevice, RxTx); - } + if (options.has_value()) { + track_uuid = uuid_getter(dispatch, hostname, process_id, did, subDevice, options); + } else { + track_uuid = uuid_getter(dispatch, hostname, process_id, did, subDevice, std::nullopt); + } - auto *packet = dispatch->trace.add_packet(); - packet->set_trusted_packet_sequence_id(TRUSTED_PACKED_SEQUENCE_ID); - packet->set_timestamp(timestamp); - auto *track_event = packet->mutable_track_event(); - track_event->set_type(perfetto_pruned::TrackEvent::TYPE_COUNTER); - track_event->set_track_uuid(track_uuid); - track_event->set_double_counter_value(value); + auto *packet = dispatch->trace.add_packet(); + packet->set_trusted_packet_sequence_id(TRUSTED_PACKED_SEQUENCE_ID); + packet->set_timestamp(timestamp); + auto *track_event = packet->mutable_track_event(); + track_event->set_type(perfetto_pruned::TrackEvent::TYPE_COUNTER); + track_event->set_track_uuid(track_uuid); + track_event->set_double_counter_value(value); } static void add_event_frequency(timeline_dispatch_t *dispatch, std::string hostname, uint64_t process_id, uint64_t thread_id, uintptr_t did, uint32_t subDevice, uint64_t timestamp, float frequency) { - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, std::nullopt, subDevice, timestamp, + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, frequency, get_frequency_track_uuuid, "Frequency"); } -static void add_event_fabricPort(timeline_dispatch_t *dispatch, std::string hostname, +static void add_event_fabricPort( timeline_dispatch_t *dispatch, std::string hostname, uint64_t process_id, uint64_t thread_id, uintptr_t did, uintptr_t hFabricPort, uint32_t subDevice, uint64_t timestamp, uint32_t fabricId, uint32_t remotePortId, float rxThroughput, float txThroughput, float rxSpeed, float txSpeed) { - - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, hFabricPort, subDevice, timestamp, - rxThroughput, get_fpThroughput_track_uuuid, "Fabric ThroughputRX", std::make_optional(false)); - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, hFabricPort, subDevice, timestamp, - txThroughput, get_fpThroughput_track_uuuid, "Fabric ThroughputTX", std::make_optional(true)); + // Define details for RX throughput. + FabricDetails details = {hFabricPort, false, fabricId, remotePortId}; + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, + rxThroughput, get_fpThroughput_track_uuuid, "Fabric ThroughputRX", details); + + details.RxTx = true; + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, + txThroughput, get_fpThroughput_track_uuuid, "Fabric ThroughputTX", details); } static void add_event_power(timeline_dispatch_t *dispatch, std::string hostname, uint64_t process_id, uint64_t thread_id, uintptr_t did, uint32_t subDevice, uint64_t timestamp, float power) { - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, std::nullopt, subDevice, timestamp, + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, power, get_power_track_uuuid, "Power"); } static void add_event_computeEU(timeline_dispatch_t *dispatch, std::string hostname, uint64_t process_id, uint64_t thread_id, uintptr_t did, uint32_t subDevice, uint64_t timestamp, float activeTime) { - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, std::nullopt, subDevice, timestamp, + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, activeTime, get_computeEU_track_uuuid, "ComputeEngine"); } static void add_event_copyEU(timeline_dispatch_t *dispatch, std::string hostname, uint64_t process_id, uint64_t thread_id, uintptr_t did, uint32_t subDevice, uint64_t timestamp, float activeTime) { - add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, std::nullopt, subDevice, timestamp, + add_event_DTelemetry(dispatch, hostname, process_id, thread_id, did, subDevice, timestamp, activeTime, get_copyEU_track_uuuid, "CopyEngine"); } @@ -457,10 +461,10 @@ static void copyEU_usr_callback(void *btx_handle, void *usr_data, const char *ho } static void fabricPort_usr_callback(void *btx_handle, void *usr_data, const char *hostname, - int64_t vpid, uint64_t vtid, int64_t ts, int64_t backend, - uint64_t did, uint64_t hFabricPort, uint32_t subDevice, - uint32_t fabricId, uint32_t remotePortId, float rxThroughput, - float txThroughput, float rxSpeed, float txSpeed) { + int64_t vpid, uint64_t vtid, int64_t ts, int64_t backend, + uint64_t did, uint64_t hFabricPort, uint32_t subDevice, + uint32_t fabricId, uint32_t remotePortId, float rxThroughput, + float txThroughput, float rxSpeed, float txSpeed) { auto *dispatch = static_cast(usr_data); add_event_fabricPort(dispatch, hostname, vpid, vtid, did, hFabricPort, subDevice, ts, fabricId, remotePortId, rxThroughput, txThroughput, rxSpeed, txSpeed);