OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 { | 544 { |
545 // FIXME: Consider returning null for loaded traces. | 545 // FIXME: Consider returning null for loaded traces. |
546 return this._targets[0]; | 546 return this._targets[0]; |
547 }, | 547 }, |
548 | 548 |
549 /** | 549 /** |
550 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 550 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
551 */ | 551 */ |
552 setEventsForTest: function(events) | 552 setEventsForTest: function(events) |
553 { | 553 { |
554 this._startCollectingTraceEvents(false); | 554 this.startCollectingTraceEvents(false); |
555 this._tracingModel.addEvents(events); | 555 this._tracingModel.addEvents(events); |
556 this.tracingComplete(); | 556 this.tracingComplete(); |
557 }, | 557 }, |
558 | 558 |
559 /** | 559 /** |
560 * @override | 560 * @override |
561 * @param {!WebInspector.Target} target | 561 * @param {!WebInspector.Target} target |
562 */ | 562 */ |
563 targetAdded: function(target) | 563 targetAdded: function(target) |
564 { | 564 { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 { | 651 { |
652 mainTarget.resourceTreeModel.resumeReload(); | 652 mainTarget.resourceTreeModel.resumeReload(); |
653 if (callback) | 653 if (callback) |
654 callback(error); | 654 callback(error); |
655 } | 655 } |
656 }, | 656 }, |
657 | 657 |
658 /** | 658 /** |
659 * @param {boolean} fromFile | 659 * @param {boolean} fromFile |
660 */ | 660 */ |
661 _startCollectingTraceEvents: function(fromFile) | 661 startCollectingTraceEvents: function(fromFile) |
662 { | 662 { |
663 this._tracingModel.reset(); | 663 this._tracingModel.reset(); |
664 this.reset(); | 664 this.reset(); |
665 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted, { fromFile: fromFile }); | 665 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted, { fromFile: fromFile }); |
666 }, | 666 }, |
667 | 667 |
668 /** | 668 /** |
669 * @override | 669 * @override |
670 */ | 670 */ |
671 tracingStarted: function() | 671 tracingStarted: function() |
672 { | 672 { |
673 this._startCollectingTraceEvents(false); | 673 this.startCollectingTraceEvents(false); |
674 }, | 674 }, |
675 | 675 |
676 /** | 676 /** |
677 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 677 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
678 * @override | 678 * @override |
679 */ | 679 */ |
680 traceEventsCollected: function(events) | 680 traceEventsCollected: function(events) |
681 { | 681 { |
682 this._tracingModel.addEvents(events); | 682 this._tracingModel.addEvents(events); |
683 }, | 683 }, |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 */ | 1341 */ |
1342 _mergeAsyncEvents: function(target, source) | 1342 _mergeAsyncEvents: function(target, source) |
1343 { | 1343 { |
1344 for (var group of source.keys()) { | 1344 for (var group of source.keys()) { |
1345 var events = target.get(group) || []; | 1345 var events = target.get(group) || []; |
1346 events = events.mergeOrdered(source.get(group) || [], WebInspector.T
racingModel.Event.compareStartAndEndTime); | 1346 events = events.mergeOrdered(source.get(group) || [], WebInspector.T
racingModel.Event.compareStartAndEndTime); |
1347 target.set(group, events); | 1347 target.set(group, events); |
1348 } | 1348 } |
1349 }, | 1349 }, |
1350 | 1350 |
1351 /** | |
1352 * @param {!Blob} file | |
1353 * @param {!WebInspector.Progress} progress | |
1354 */ | |
1355 loadFromFile: function(file, progress) | |
1356 { | |
1357 var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this,
progress); | |
1358 var fileReader = this._createFileReader(file, delegate); | |
1359 var loader = new WebInspector.TracingModelLoader(this, new WebInspector.
ProgressProxy(null), fileReader.cancel.bind(fileReader)); | |
1360 fileReader.start(loader); | |
1361 }, | |
1362 | |
1363 /** | |
1364 * @param {string} url | |
1365 * @param {!WebInspector.Progress} progress | |
1366 */ | |
1367 loadFromURL: function(url, progress) | |
1368 { | |
1369 var stream = new WebInspector.TracingModelLoader(this, progress); | |
1370 WebInspector.ResourceLoader.loadAsStream(url, null, stream); | |
1371 }, | |
1372 | |
1373 _createFileReader: function(file, delegate) | |
1374 { | |
1375 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineMod
el.TransferChunkLengthBytes, delegate); | |
1376 }, | |
1377 | |
1378 reset: function() | 1351 reset: function() |
1379 { | 1352 { |
1380 this._virtualThreads = []; | 1353 this._virtualThreads = []; |
1381 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ | 1354 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ |
1382 this._mainThreadEvents = []; | 1355 this._mainThreadEvents = []; |
1383 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac
ingModel.AsyncEvent>>} */ | 1356 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac
ingModel.AsyncEvent>>} */ |
1384 this._mainThreadAsyncEventsByGroup = new Map(); | 1357 this._mainThreadAsyncEventsByGroup = new Map(); |
1385 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ | 1358 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ |
1386 this._inspectedTargetEvents = []; | 1359 this._inspectedTargetEvents = []; |
1387 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ | 1360 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 accept: function(event) | 1593 accept: function(event) |
1621 { | 1594 { |
1622 return this._visibleTypes.has(WebInspector.TimelineModel._eventType(even
t)); | 1595 return this._visibleTypes.has(WebInspector.TimelineModel._eventType(even
t)); |
1623 }, | 1596 }, |
1624 | 1597 |
1625 __proto__: WebInspector.TimelineModel.Filter.prototype | 1598 __proto__: WebInspector.TimelineModel.Filter.prototype |
1626 } | 1599 } |
1627 | 1600 |
1628 /** | 1601 /** |
1629 * @constructor | 1602 * @constructor |
1630 * @implements {WebInspector.OutputStreamDelegate} | |
1631 * @param {!WebInspector.TimelineModel} model | |
1632 * @param {!WebInspector.Progress} progress | |
1633 */ | |
1634 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) | |
1635 { | |
1636 this._model = model; | |
1637 this._progress = progress; | |
1638 } | |
1639 | |
1640 WebInspector.TimelineModelLoadFromFileDelegate.prototype = { | |
1641 /** | |
1642 * @override | |
1643 */ | |
1644 onTransferStarted: function() | |
1645 { | |
1646 this._progress.setTitle(WebInspector.UIString("Loading\u2026")); | |
1647 }, | |
1648 | |
1649 /** | |
1650 * @override | |
1651 * @param {!WebInspector.ChunkedReader} reader | |
1652 */ | |
1653 onChunkTransferred: function(reader) | |
1654 { | |
1655 if (this._progress.isCanceled()) { | |
1656 reader.cancel(); | |
1657 this._progress.done(); | |
1658 this._model.reset(); | |
1659 return; | |
1660 } | |
1661 | |
1662 var totalSize = reader.fileSize(); | |
1663 if (totalSize) { | |
1664 this._progress.setTotalWork(totalSize); | |
1665 this._progress.setWorked(reader.loadedSize()); | |
1666 } | |
1667 }, | |
1668 | |
1669 /** | |
1670 * @override | |
1671 */ | |
1672 onTransferFinished: function() | |
1673 { | |
1674 this._progress.done(); | |
1675 }, | |
1676 | |
1677 /** | |
1678 * @override | |
1679 * @param {!WebInspector.ChunkedReader} reader | |
1680 * @param {!Event} event | |
1681 */ | |
1682 onError: function(reader, event) | |
1683 { | |
1684 this._progress.done(); | |
1685 this._model.reset(); | |
1686 switch (event.target.error.code) { | |
1687 case FileError.NOT_FOUND_ERR: | |
1688 WebInspector.console.error(WebInspector.UIString("File \"%s\" not fo
und.", reader.fileName())); | |
1689 break; | |
1690 case FileError.NOT_READABLE_ERR: | |
1691 WebInspector.console.error(WebInspector.UIString("File \"%s\" is not
readable", reader.fileName())); | |
1692 break; | |
1693 case FileError.ABORT_ERR: | |
1694 break; | |
1695 default: | |
1696 WebInspector.console.error(WebInspector.UIString("An error occurred
while reading the file \"%s\"", reader.fileName())); | |
1697 } | |
1698 } | |
1699 } | |
1700 | |
1701 /** | |
1702 * @constructor | |
1703 * @extends {WebInspector.TimelineModel.Filter} | 1603 * @extends {WebInspector.TimelineModel.Filter} |
1704 * @param {!Array<string>} excludeNames | 1604 * @param {!Array<string>} excludeNames |
1705 */ | 1605 */ |
1706 WebInspector.ExclusiveNameFilter = function(excludeNames) | 1606 WebInspector.ExclusiveNameFilter = function(excludeNames) |
1707 { | 1607 { |
1708 WebInspector.TimelineModel.Filter.call(this); | 1608 WebInspector.TimelineModel.Filter.call(this); |
1709 this._excludeNames = new Set(excludeNames); | 1609 this._excludeNames = new Set(excludeNames); |
1710 } | 1610 } |
1711 | 1611 |
1712 WebInspector.ExclusiveNameFilter.prototype = { | 1612 WebInspector.ExclusiveNameFilter.prototype = { |
(...skipping 27 matching lines...) Expand all Loading... |
1740 */ | 1640 */ |
1741 accept: function(event) | 1641 accept: function(event) |
1742 { | 1642 { |
1743 return !WebInspector.TracingModel.isTopLevelEvent(event); | 1643 return !WebInspector.TracingModel.isTopLevelEvent(event); |
1744 }, | 1644 }, |
1745 | 1645 |
1746 __proto__: WebInspector.TimelineModel.Filter.prototype | 1646 __proto__: WebInspector.TimelineModel.Filter.prototype |
1747 } | 1647 } |
1748 | 1648 |
1749 /** | 1649 /** |
1750 * @constructor | |
1751 * @implements {WebInspector.OutputStream} | |
1752 * @param {!WebInspector.TimelineModel} model | |
1753 * @param {!WebInspector.Progress} progress | |
1754 * @param {function()=} canceledCallback | |
1755 */ | |
1756 WebInspector.TracingModelLoader = function(model, progress, canceledCallback) | |
1757 { | |
1758 this._model = model; | |
1759 | |
1760 this._canceledCallback = canceledCallback; | |
1761 this._progress = progress; | |
1762 this._progress.setTitle(WebInspector.UIString("Loading")); | |
1763 this._progress.setTotalWork(WebInspector.TracingModelLoader._totalProgress);
// Unknown, will loop the values. | |
1764 | |
1765 this._state = WebInspector.TracingModelLoader.State.Initial; | |
1766 this._buffer = ""; | |
1767 this._firstChunk = true; | |
1768 this._wasCanceledOnce = false; | |
1769 | |
1770 this._loadedBytes = 0; | |
1771 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this.
_writeBalancedJSON.bind(this), true); | |
1772 } | |
1773 | |
1774 WebInspector.TracingModelLoader._totalProgress = 100000; | |
1775 | |
1776 WebInspector.TracingModelLoader.State = { | |
1777 Initial: "Initial", | |
1778 LookingForEvents: "LookingForEvents", | |
1779 ReadingEvents: "ReadingEvents" | |
1780 } | |
1781 | |
1782 WebInspector.TracingModelLoader.prototype = { | |
1783 /** | |
1784 * @override | |
1785 * @param {string} chunk | |
1786 */ | |
1787 write: function(chunk) | |
1788 { | |
1789 this._loadedBytes += chunk.length; | |
1790 if (this._progress.isCanceled() && !this._wasCanceledOnce) { | |
1791 this._wasCanceled = true; | |
1792 this._reportErrorAndCancelLoading(); | |
1793 return; | |
1794 } | |
1795 this._progress.setWorked(this._loadedBytes % WebInspector.TracingModelLo
ader._totalProgress, | |
1796 WebInspector.UIString("Loaded %s", Number.bytes
ToString(this._loadedBytes))); | |
1797 if (this._state === WebInspector.TracingModelLoader.State.Initial) { | |
1798 if (chunk[0] === "{") | |
1799 this._state = WebInspector.TracingModelLoader.State.LookingForEv
ents; | |
1800 else if (chunk[0] === "[") | |
1801 this._state = WebInspector.TracingModelLoader.State.ReadingEvent
s; | |
1802 else { | |
1803 this._reportErrorAndCancelLoading(WebInspector.UIString("Malform
ed timeline data: Unknown JSON format")); | |
1804 return; | |
1805 } | |
1806 } | |
1807 | |
1808 if (this._state === WebInspector.TracingModelLoader.State.LookingForEven
ts) { | |
1809 var objectName = "\"traceEvents\":"; | |
1810 var startPos = this._buffer.length - objectName.length; | |
1811 this._buffer += chunk; | |
1812 var pos = this._buffer.indexOf(objectName, startPos); | |
1813 if (pos === -1) | |
1814 return; | |
1815 chunk = this._buffer.slice(pos + objectName.length) | |
1816 this._state = WebInspector.TracingModelLoader.State.ReadingEvents; | |
1817 } | |
1818 | |
1819 this._jsonTokenizer.write(chunk); | |
1820 }, | |
1821 | |
1822 /** | |
1823 * @param {string} data | |
1824 */ | |
1825 _writeBalancedJSON: function(data) | |
1826 { | |
1827 var json = data + "]"; | |
1828 | |
1829 if (this._firstChunk) { | |
1830 this._model._startCollectingTraceEvents(true); | |
1831 } else { | |
1832 var commaIndex = json.indexOf(","); | |
1833 if (commaIndex !== -1) | |
1834 json = json.slice(commaIndex + 1); | |
1835 json = "[" + json; | |
1836 } | |
1837 | |
1838 var items; | |
1839 try { | |
1840 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload
>} */ (JSON.parse(json)); | |
1841 } catch (e) { | |
1842 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: %s", e.toString())); | |
1843 return; | |
1844 } | |
1845 | |
1846 if (this._firstChunk) { | |
1847 this._firstChunk = false; | |
1848 if (this._looksLikeAppVersion(items[0])) { | |
1849 this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy
Timeline format is not supported.")); | |
1850 return; | |
1851 } | |
1852 } | |
1853 | |
1854 try { | |
1855 this._model._tracingModel.addEvents(items); | |
1856 } catch(e) { | |
1857 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: %s", e.toString())); | |
1858 return; | |
1859 } | |
1860 }, | |
1861 | |
1862 /** | |
1863 * @param {string=} message | |
1864 */ | |
1865 _reportErrorAndCancelLoading: function(message) | |
1866 { | |
1867 if (message) | |
1868 WebInspector.console.error(message); | |
1869 this._model.tracingComplete(); | |
1870 this._model.reset(); | |
1871 if (this._canceledCallback) | |
1872 this._canceledCallback(); | |
1873 this._progress.done(); | |
1874 }, | |
1875 | |
1876 _looksLikeAppVersion: function(item) | |
1877 { | |
1878 return typeof item === "string" && item.indexOf("Chrome") !== -1; | |
1879 }, | |
1880 | |
1881 /** | |
1882 * @override | |
1883 */ | |
1884 close: function() | |
1885 { | |
1886 this._model._loadedFromFile = true; | |
1887 this._model.tracingComplete(); | |
1888 if (this._progress) | |
1889 this._progress.done(); | |
1890 } | |
1891 } | |
1892 | |
1893 /** | |
1894 * @constructor | |
1895 * @param {!WebInspector.OutputStream} stream | |
1896 * @implements {WebInspector.OutputStreamDelegate} | |
1897 */ | |
1898 WebInspector.TracingTimelineSaver = function(stream) | |
1899 { | |
1900 this._stream = stream; | |
1901 } | |
1902 | |
1903 WebInspector.TracingTimelineSaver.prototype = { | |
1904 /** | |
1905 * @override | |
1906 */ | |
1907 onTransferStarted: function() | |
1908 { | |
1909 this._stream.write("["); | |
1910 }, | |
1911 | |
1912 /** | |
1913 * @override | |
1914 */ | |
1915 onTransferFinished: function() | |
1916 { | |
1917 this._stream.write("]"); | |
1918 }, | |
1919 | |
1920 /** | |
1921 * @override | |
1922 * @param {!WebInspector.ChunkedReader} reader | |
1923 */ | |
1924 onChunkTransferred: function(reader) { }, | |
1925 | |
1926 /** | |
1927 * @override | |
1928 * @param {!WebInspector.ChunkedReader} reader | |
1929 * @param {!Event} event | |
1930 */ | |
1931 onError: function(reader, event) { } | |
1932 } | |
1933 | |
1934 /** | |
1935 * @constructor | 1650 * @constructor |
1936 * @param {!WebInspector.TracingModel.Event} event | 1651 * @param {!WebInspector.TracingModel.Event} event |
1937 */ | 1652 */ |
1938 WebInspector.InvalidationTrackingEvent = function(event) | 1653 WebInspector.InvalidationTrackingEvent = function(event) |
1939 { | 1654 { |
1940 /** @type {string} */ | 1655 /** @type {string} */ |
1941 this.type = event.name; | 1656 this.type = event.name; |
1942 /** @type {number} */ | 1657 /** @type {number} */ |
1943 this.startTime = event.startTime; | 1658 this.startTime = event.startTime; |
1944 /** @type {!WebInspector.TracingModel.Event} */ | 1659 /** @type {!WebInspector.TracingModel.Event} */ |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 if (!id) | 2007 if (!id) |
2293 return; | 2008 return; |
2294 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */ | 2009 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */ |
2295 var initiatorMap = this._initiatorByType.get(initiatorType); | 2010 var initiatorMap = this._initiatorByType.get(initiatorType); |
2296 if (isInitiator) | 2011 if (isInitiator) |
2297 initiatorMap.set(id, event); | 2012 initiatorMap.set(id, event); |
2298 else | 2013 else |
2299 event.initiator = initiatorMap.get(id) || null; | 2014 event.initiator = initiatorMap.get(id) || null; |
2300 } | 2015 } |
2301 } | 2016 } |
OLD | NEW |