|
526 | 526 | _loadedTraceEents: Object, |
527 | 527 | _fullBounds: Object, |
528 | 528 | _isLoading: {type: Boolean, value: false}, |
| 529 | + _isCounterEventsLoading: {type: Boolean, value: false}, |
529 | 530 | _dirty: {type: Boolean, value: false}, |
530 | 531 | _tasks: Object, |
| 532 | + _counterEventsOffset: {type: Number, value: 0}, |
531 | 533 | _model: Object, |
532 | 534 | _resolution: {type: Number, value: 1000}, |
533 | 535 | _filteredByVisibility: {type: Boolean, value: false}, |
|
1815 | 1817 | let startUpdateView; |
1816 | 1818 |
|
1817 | 1819 | try { |
1818 | | - const data = await this._loadJSON(requestedRange) |
| 1820 | + const data = await this._loadJSON(requestedRange); |
1819 | 1821 | if (!this._isOss) { |
1820 | 1822 | this._addInitialResponseDataLatency(performance.now()); |
1821 | 1823 | this._addDataResponseSize(data.length); |
1822 | 1824 | } |
1823 | 1825 | startUpdateModel = performance.now(); |
1824 | 1826 | const jsonData = JSON.parse(data); |
| 1827 | + this._maybeFetchMoreCounterEvents(jsonData); |
1825 | 1828 | this._codeLink = jsonData['codeLink']; |
1826 | 1829 | if (!this._model /* first load */) { |
1827 | 1830 | this._collapseBigProcessTracks(jsonData); |
|
1947 | 1950 | if (!jsonData['returnedEventsSize']) { |
1948 | 1951 | this._displayOverlay('Trace Viewer', 'No trace events data returned.'); |
1949 | 1952 | } |
1950 | | - if (jsonData['showCounterMessage'].length > 0) { |
1951 | | - this._displayOverlay('Counters: ', jsonData['showCounterMessage']); |
1952 | | - } |
1953 | 1953 | this._dirty = true; |
1954 | 1954 | this._model = new tr.Model(); |
1955 | 1955 | this._loadedTraceEvents = new Set(); |
|
2012 | 2012 | let eventsToAdd = []; |
2013 | 2013 | jsonData.traceEvents.forEach(event => { |
2014 | 2014 | if (event.entries) { |
| 2015 | + let groupedCounterEventsStartTime = performance.now(); |
2015 | 2016 | // Handle Grouped Counter Events |
2016 | 2017 | let argName = event.event_stats; |
2017 | 2018 | event.entries.forEach(entry => { |
|
2026 | 2027 | }; |
2027 | 2028 | eventsToAdd.push(newEvent); |
2028 | 2029 | }); |
| 2030 | + this._addProcessGroupCouterLatency(performance.now() - groupedCounterEventsStartTime); |
2029 | 2031 | } else { |
2030 | 2032 | // Handle Regular Events |
2031 | 2033 | eventsToAdd.push(event); |
|
2047 | 2049 | } |
2048 | 2050 | window.parent.postMessage({'type': 'processes-list','data': processList,}, '*'); |
2049 | 2051 | }, |
| 2052 | + // Some sessions may have counter events that are not returned in the initial response. |
| 2053 | + // This function sends a request to fetch more counter events if the offset is set in the |
| 2054 | + // response. This is done using the counter events offset returned in the initial response. |
| 2055 | + // The counter events offset is set to 0 from the backend, which will stop subsequent fetches. |
| 2056 | + _maybeFetchMoreCounterEvents: function(jsonData) { |
| 2057 | + if (!jsonData['counterEventsOffset'] || jsonData['counterEventsOffset'] === 0) { |
| 2058 | + // console.log("Progressive loading: No more counter events available."); |
| 2059 | + return; |
| 2060 | + } |
| 2061 | + // console.log("Progressive loading: More counter events available. Offset:", jsonData['counterEventsOffset']); |
| 2062 | + this._counterEventsOffset = jsonData['counterEventsOffset']; |
| 2063 | + this._replaceModel = false; |
| 2064 | + const requestURL = this._buildBaseURL(); |
| 2065 | + const requestedRange = null; |
| 2066 | + let retries = 5; |
| 2067 | + let moreCounterEventsStartTime = performance.now(); |
| 2068 | + const fetchWithRetry = async () => { |
| 2069 | + try { |
| 2070 | + const data = await this._loadJSON(requestedRange); |
| 2071 | + this._addFetchCounterEventsLatency(performance.now() - moreCounterEventsStartTime); |
| 2072 | + const jsonData = JSON.parse(data); |
| 2073 | + // console.log("Progressive loading: Counter events fetched. New offset:", jsonData['counterEventsOffset']); |
| 2074 | + // console.log("Progressive loading: All counter events loaded. Updating view."); |
| 2075 | + return jsonData; |
| 2076 | + } catch (error) { |
| 2077 | + if (retries > 0) { |
| 2078 | + retries--; |
| 2079 | + console.error('Failed to fetch more counter events, retrying...', error); |
| 2080 | + await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second before retrying |
| 2081 | + return fetchWithRetry(); |
| 2082 | + } else { |
| 2083 | + console.error('Failed to fetch more counter events after multiple retries:', error); |
| 2084 | + this._displayOverlay('Error', 'Failed to fetch more counter events.'); |
| 2085 | + return null; |
| 2086 | + } |
| 2087 | + } |
| 2088 | + }; |
| 2089 | + this._isCounterEventsLoading = true; // Set loading to true |
| 2090 | + fetchWithRetry().then(jsonData => { |
| 2091 | + this._isCounterEventsLoading = false; // Set loading to false |
| 2092 | + if (jsonData) { |
| 2093 | + this._updateModel(jsonData, /* replaceModel= */ false); |
| 2094 | + if (jsonData['counterEventsOffset'] === 0) { |
| 2095 | + this._updateView(this._loadedRange); |
| 2096 | + } |
| 2097 | + window.parent.gtag && window.parent.gtag('event', 'tv-counter-events-reload', { |
| 2098 | + 'screen_name': 'trace viewer', |
| 2099 | + 'event_category': 'reload', |
| 2100 | + 'event_label': 'counter_events_reload', |
| 2101 | + 'event_variable': requestURL.toString()}); |
| 2102 | + } |
| 2103 | + }); |
| 2104 | + }, |
2050 | 2105 |
|
2051 | 2106 | // Updates the view based on the current model. |
2052 | 2107 | _updateView: async function(requestedRange) { |
| 2108 | + // console.log("updateView: requestedRange:", requestedRange); |
2053 | 2109 | if (requestedRange == null) { |
2054 | 2110 | this._loadedRange = tf_component_traceviewer.expand( |
2055 | 2111 | this._fullBounds, |
|
2100 | 2156 | node.value = latency; |
2101 | 2157 | }, |
2102 | 2158 |
|
| 2159 | + _addProcessGroupCouterLatency: function(latency) { |
| 2160 | + const node = parent.document.getElementById('process-group-counter-latency'); |
| 2161 | + node.value = latency; |
| 2162 | + }, |
| 2163 | + |
| 2164 | + _addFetchCounterEventsLatency: function(latency) { |
| 2165 | + const node = parent.document.getElementById('fetch-counter-events-latency'); |
| 2166 | + node.value = latency; |
| 2167 | + }, |
| 2168 | + |
2103 | 2169 | // Access the {min, max} range of a trackView. |
2104 | 2170 | _trackViewRange: function(trackView) { |
2105 | 2171 | return this._calcViewportRange(trackView.viewport.currentDisplayTransform, trackView.viewWidth_); |
|
2182 | 2248 | } |
2183 | 2249 | requestURL.searchParams.set('replace_model', this._replaceModel); |
2184 | 2250 | requestURL.searchParams.set('new_backend', this._useNewBackend); |
| 2251 | + requestURL.searchParams.set('counter_events_offset', this._counterEventsOffset); |
2185 | 2252 | return requestURL; |
2186 | 2253 | }, |
2187 | 2254 |
|
|
0 commit comments