1 // Copyright 2018 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef THIRD_PARTY_QUIC_TRACE_TOOLS_PROCESSED_TRACE_H_ 16 #define THIRD_PARTY_QUIC_TRACE_TOOLS_PROCESSED_TRACE_H_ 17 18 #include "absl/container/flat_hash_map.h" 19 #include "absl/container/flat_hash_set.h" 20 #include "quic_trace/analysis/trace_numbering.h" 21 #include "quic_trace/quic_trace.pb.h" 22 #include "tools/render/table.h" 23 #include "tools/render/trace_renderer.h" 24 25 namespace quic_trace { 26 namespace render { 27 28 // Stores a QUIC trace with additional information required to show useful 29 // information about portions of the trace and individual packets. 30 class ProcessedTrace { 31 public: 32 struct PacketSearchResult { 33 // Index of the packet that can be supplied to the renderer. 34 ptrdiff_t index = -1; 35 const Box* as_rendered = nullptr; 36 const Event* event = nullptr; 37 }; 38 39 // Preprocesses all of information in the trace and populates the |renderer| 40 // object. 41 ProcessedTrace(std::unique_ptr<Trace> trace, TraceRenderer* renderer); 42 43 // Populates the summary table for (start_time, end_time) range, or returns 44 // false if the range is empty. 45 bool SummaryTable(Table* table, float start_time, float end_time); 46 47 // Finds the packet containing the specified point and returns the offset in 48 // the array of all packet boxes drawn, or -1 if it's outside any of the 49 // points. |margin| specifies the size (in trace units) by which every packet 50 // box is extended for purpose of this search (if multiple boxes are matched, 51 // the closest one is returned). 52 PacketSearchResult FindPacketContainingPoint(vec2 point, vec2 margin); 53 54 void FillTableForPacket(Table* table, 55 const Box* as_rendered, 56 const Event* packet); 57 58 // For specified section of the graph, find a bounding box that contains all 59 // of the packets in it, or return nullopt if none are contained. 60 absl::optional<Box> BoundContainedPackets(Box boundary); 61 62 private: 63 struct RenderedPacket { 64 Box box; 65 const Event* packet; 66 67 bool operator<(const RenderedPacket& other) const { 68 return box.origin.x < other.box.origin.x; 69 } 70 }; 71 72 struct VectorHash { operatorVectorHash73 size_t operator()(vec2 vector) const { 74 return std::hash<float>()(vector.x) + std::hash<float>()(vector.y); 75 } 76 }; 77 78 void AddPacket(TraceRenderer* renderer, 79 const Event& packet, 80 Interval interval, 81 PacketType type); 82 83 absl::flat_hash_set<uint64_t>* GetPacketsAcked(const EncryptionLevel); 84 absl::flat_hash_set<uint64_t>* GetPacketsLost(const EncryptionLevel); 85 86 std::unique_ptr<Trace> trace_; 87 absl::flat_hash_set<uint64_t> packets_acked_initial_; 88 absl::flat_hash_set<uint64_t> packets_acked_handshake_; 89 absl::flat_hash_set<uint64_t> packets_acked_1rtt_; 90 absl::flat_hash_set<uint64_t> packets_lost_initial_; 91 absl::flat_hash_set<uint64_t> packets_lost_handshake_; 92 absl::flat_hash_set<uint64_t> packets_lost_1rtt_; 93 // Map from packet-as-drawn offset to the ack. This is required because 94 // unlike sent or lost packets, there could be many acks derived from the same 95 // Event object. 96 absl::flat_hash_map<vec2, uint64_t, VectorHash> acks_; 97 std::vector<RenderedPacket> rendered_packets_; 98 }; 99 100 } // namespace render 101 } // namespace quic_trace 102 103 #endif // THIRD_PARTY_QUIC_TRACE_TOOLS_PROCESSED_TRACE_H_ 104