From 793b100dfc3d2320cf180eac364dc04e9eec204a Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 6 Apr 2020 08:41:27 -0700 Subject: [PATCH] Export last few lines of the logs Summary: This diff exports the last 30 mins of logs. I noticed that the export can become massive, if Flipper is running for a long time and if all the logs are exported. Due to this I have noticed that the byte size of the exports has been huge and most probably causing out of emory exception in our end point to upload the trace. Just exporting Logs plugin, size of Flipper trace is 1.8MB, mind that my Flipper was just open for few mins. {F233265050} Look at [this](https://our.intern.facebook.com/intern/scuba/query/?dataset=infinity_analytics_events&drillstate=%7B%22sampleCols%22%3A[%22infinity_version%22%2C%22session_id%22%2C%22data%22%2C%22time%22%2C%22is_headless%22%2C%22platform%22%2C%22plugin%22%2C%22namespace_version%22%2C%22arch%22%2C%22gatekeepers%22%2C%22fbid%22%2C%22event%22%2C%22type%22%2C%22namespace%22%2C%22electron_version%22%2C%22node_version%22]%2C%22cols%22%3A[%22fbid%22]%2C%22derivedCols%22%3A[]%2C%22mappedCols%22%3A[]%2C%22enumCols%22%3A[]%2C%22return_remainder%22%3Afalse%2C%22should_pivot%22%3Afalse%2C%22is_timeseries%22%3Afalse%2C%22hideEmptyColumns%22%3Afalse%2C%22start%22%3A%22-1%20week%22%2C%22samplingRatio%22%3A1%2C%22compare%22%3A%22none%22%2C%22should_transpose%22%3Afalse%2C%22dimensions%22%3A[%22event%22]%2C%22num_samples%22%3A%22100%22%2C%22metric%22%3A%22count%22%2C%22top%22%3A50%2C%22timezone%22%3A%22America%2FLos_Angeles%22%2C%22end%22%3A%22now%22%2C%22aggregateList%22%3A[]%2C%22param_dimensions%22%3A[]%2C%22modifiers%22%3A[]%2C%22order%22%3A%22none%22%2C%22order_desc%22%3Atrue%2C%22filterMode%22%3A%22DEFAULT%22%2C%22constraints%22%3A[[%7B%22column%22%3A%22type%22%2C%22op%22%3A%22eq%22%2C%22value%22%3A[%22[%5C%22usage%5C%22]%22]%7D%2C%7B%22column%22%3A%22fbid%22%2C%22op%22%3A%22eq%22%2C%22value%22%3A[%22[%5C%22100001214797081%5C%22]%22]%7D%2C%7B%22column%22%3A%22event%22%2C%22op%22%3A%22eq%22%2C%22value%22%3A[%22[%5C%22export-url%3Atrace-size%5C%22]%22]%7D]]%2C%22c_constraints%22%3A[[]]%2C%22b_constraints%22%3A[[]]%2C%22metrik_view_params%22%3A%7B%22should_use_legacy_colors%22%3Afalse%2C%22columns_skip_formatting%22%3A[]%2C%22view%22%3A%22samples_client%22%2C%22width%22%3A%222110%22%2C%22height%22%3A%221300%22%2C%22tableID%22%3A%22infinity_analytics_events%22%2C%22tooltip_outside%22%3Atrue%2C%22fitToContent%22%3Afalse%2C%22format_tooltip_in_percent%22%3Afalse%2C%22pocs%22%3A[%7B%22poc_label%22%3A%22Point%20of%20contact%22%2C%22poc_id%22%3A%22100002006986037%22%7D]%2C%22state%22%3A%22published%22%2C%22use_y_axis_hints_as_limits%22%3Atrue%2C%22has_dynamic_context_menu%22%3Atrue%2C%22has_context_menu%22%3Afalse%2C%22legend_mode%22%3A%22nongrid%22%2C%22title%22%3A%22Support%20Form%20V2%20Events%22%2C%22timezone_offset%22%3A420%2C%22y_min_hint%22%3A0%2C%22should_render_plugins_menu%22%3Afalse%2C%22title_use_v2%22%3Atrue%7D%7D&pool=uber&view=samples_client&dashboard_id&tab_id&widget_id&widget_piece_id), the size of the export is 194 MB. Reviewed By: jknoxville Differential Revision: D20868701 fbshipit-source-id: 1f041d11fc9cab93cdd1f1a28f15fa557b51fc75 --- desktop/app/src/devices/BaseDevice.tsx | 8 ++++++-- desktop/app/src/utils/exportData.tsx | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/desktop/app/src/devices/BaseDevice.tsx b/desktop/app/src/devices/BaseDevice.tsx index f57fc81fc..909a00017 100644 --- a/desktop/app/src/devices/BaseDevice.tsx +++ b/desktop/app/src/devices/BaseDevice.tsx @@ -134,8 +134,12 @@ export default class BaseDevice { this._notifyLogListeners(entry); } - getLogs() { - return this.logEntries; + getLogs(startDate: Date | null = null) { + return startDate != null + ? this.logEntries.filter((log) => { + return log.date > startDate; + }) + : this.logEntries; } clearLogs(): Promise { diff --git a/desktop/app/src/utils/exportData.tsx b/desktop/app/src/utils/exportData.tsx index 7c42371c7..82955a002 100644 --- a/desktop/app/src/utils/exportData.tsx +++ b/desktop/app/src/utils/exportData.tsx @@ -294,7 +294,11 @@ const addSaltToDeviceSerial = async ( deviceType: device.deviceType, title: device.title, os: device.os, - logEntries: selectedPlugins.includes('DeviceLogs') ? device.getLogs() : [], + logEntries: selectedPlugins.includes('DeviceLogs') + ? device.getLogs( + new Date(new Date().getTime() - 1000 * 60 * 10), // Last 10 mins of logs + ) + : [], screenshotHandle: deviceScreenshot, }); statusUpdate &&