Sui Chen | b53fa1b | 2022-05-26 00:16:42 -0700 | [diff] [blame] | 1 | const { ipcRenderer } = require('electron'); |
Sui Chen | b65280f | 2020-06-30 18:14:03 -0700 | [diff] [blame] | 2 | const { spawnSync } = require('child_process'); |
| 3 | const md5File = require('md5-file'); |
| 4 | const https = require('https'); |
| 5 | |
Sui Chen | b53fa1b | 2022-05-26 00:16:42 -0700 | [diff] [blame] | 6 | ipcRenderer.on('filename', (event, x) => { |
Sui Chen | b65280f | 2020-06-30 18:14:03 -0700 | [diff] [blame] | 7 | // Determine file type |
| 8 | let is_asio_log = false; |
| 9 | const data = fs.readFileSync(x, {encoding: 'utf-8'}); |
| 10 | let lines = data.split('\n'); |
| 11 | for (let i = 0; i < lines.length; i++) { |
| 12 | if (lines[i].indexOf('@asio') == 0) { |
| 13 | is_asio_log = true; |
| 14 | break; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | if (is_asio_log) { |
| 19 | ShowBlocker('Loading Boost ASIO handler tracking log'); |
| 20 | console.log('This file is a Boost Asio handler tracking log'); |
| 21 | ParseBoostHandlerTimeline(data); |
| 22 | OnGroupByConditionChanged_ASIO(); |
| 23 | if (boost_asio_handler_timeline_view.IsEmpty() == false) { |
| 24 | boost_asio_handler_timeline_view.CurrentFileName = x; |
| 25 | HideWelcomeScreen(); |
| 26 | ShowASIOTimeline(); |
| 27 | ShowNavigation(); |
| 28 | UpdateFileNamesString(); |
| 29 | } |
| 30 | HideBlocker(); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | OpenDBusPcapFile(x); |
Sui Chen | b65280f | 2020-06-30 18:14:03 -0700 | [diff] [blame] | 35 | UpdateLayout(); |
Sui Chen | b53fa1b | 2022-05-26 00:16:42 -0700 | [diff] [blame] | 36 | }); |
| 37 | |
| 38 | function OpenFileHandler() { |
| 39 | ipcRenderer.send('file-request'); |
Sui Chen | b65280f | 2020-06-30 18:14:03 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // The file may be either DBus dump or Boost Asio handler log |
| 43 | document.getElementById('btn_open_file') |
| 44 | .addEventListener('click', OpenFileHandler); |
| 45 | document.getElementById('btn_open_file2') |
| 46 | .addEventListener('click', OpenFileHandler); |
| 47 | |
| 48 | document.getElementById('bah1').addEventListener( |
| 49 | 'click', OnGroupByConditionChanged_ASIO); |
| 50 | document.getElementById('bah2').addEventListener( |
| 51 | 'click', OnGroupByConditionChanged_ASIO); |
| 52 | document.getElementById('bah3').addEventListener( |
| 53 | 'click', OnGroupByConditionChanged_ASIO); |
| 54 | |
| 55 | // UI elements |
| 56 | var g_group_by_dbus = document.getElementById('span_group_by_dbus'); |
| 57 | var g_group_by_ipmi = document.getElementById('span_group_by_ipmi'); |
| 58 | var g_group_by_asio = |
| 59 | document.getElementById('span_group_by_boost_asio_handler') |
| 60 | var g_canvas_ipmi = document.getElementById('my_canvas_ipmi'); |
| 61 | var g_canvas_dbus = document.getElementById('my_canvas_dbus'); |
| 62 | var g_canvas_asio = document.getElementById('my_canvas_boost_asio_handler'); |
| 63 | |
| 64 | var g_dbus_pcap_status_content = document.getElementById('dbus_pcap_status_content'); |
| 65 | var g_dbus_pcap_error_content = document.getElementById('dbus_pcap_error_content'); |
| 66 | var g_btn_download_dbus_pcap = document.getElementById('btn_download_dbus_pcap'); |
| 67 | var g_welcome_screen_content = document.getElementById('welcome_screen_content'); |
| 68 | var g_scapy_error_content = document.getElementById('scapy_error_content'); |
| 69 | |
| 70 | var g_btn_zoom_reset = document.getElementById('btn_zoom_reset'); |
| 71 | |
| 72 | function DownloadDbusPcap() { |
| 73 | const url = 'https://raw.githubusercontent.com/openbmc/openbmc-tools/08ce0a5bad2b5c970af567c2e9888d444afe3946/dbus-pcap/dbus-pcap'; |
| 74 | |
| 75 | https.get(url, (res) => { |
| 76 | const path = 'dbus-pcap'; |
| 77 | const file_path = fs.createWriteStream(path); |
| 78 | res.pipe(file_path); |
| 79 | file_path.on('finish', () => { |
| 80 | file_path.close(); |
| 81 | alert("dbus-pcap download complete!"); |
| 82 | CheckDbusPcapPresence(); |
| 83 | }); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | g_btn_download_dbus_pcap.addEventListener( |
| 88 | 'click', DownloadDbusPcap); |
| 89 | |
| 90 | function ShowDBusTimeline() { |
| 91 | g_canvas_dbus.style.display = 'block'; |
| 92 | g_group_by_dbus.style.display = 'block'; |
| 93 | } |
| 94 | function ShowIPMITimeline() { |
| 95 | g_canvas_ipmi.style.display = 'block'; |
| 96 | g_group_by_ipmi.style.display = 'block'; |
| 97 | } |
| 98 | function ShowASIOTimeline() { |
| 99 | g_canvas_asio.style.display = 'block'; |
| 100 | g_group_by_asio.style.display = 'block'; |
| 101 | } |
| 102 | |
| 103 | // Make sure the user has scapy.all installed |
| 104 | function IsPythonInstallationOK() { |
| 105 | const x = spawnSync('python3', ['-m', 'scapy.all']); |
| 106 | return (x.status == 0); |
| 107 | } |
| 108 | |
| 109 | function IsDbusPcapPresent() { |
| 110 | // This should exist if the openbmc-tools repository |
| 111 | // is checked out as a whole |
| 112 | const dbus_pcap = '../dbus-pcap/dbus-pcap'; |
| 113 | |
| 114 | if (fs.existsSync('dbus-pcap')) { |
| 115 | return true; |
| 116 | } else if (fs.existsSync(dbus_pcap)) { // Create symlink |
| 117 | fs.symlinkSync(dbus_pcap, './dbus-pcap'); |
| 118 | return true; |
| 119 | } else { |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | function CheckDependencies() { |
| 125 | g_dbus_pcap_status_content.style.display = 'none'; |
| 126 | g_dbus_pcap_error_content.style.display = 'none'; |
| 127 | g_scapy_error_content.style.display = 'none'; |
| 128 | g_welcome_screen_content.style.display = 'none'; |
| 129 | |
| 130 | const dbus_pcap_ok = IsDbusPcapPresent(); |
| 131 | if (!dbus_pcap_ok) { |
| 132 | g_dbus_pcap_error_content.style.display = 'block'; |
| 133 | } |
| 134 | |
| 135 | const scapy_ok = IsPythonInstallationOK(); |
| 136 | if (!scapy_ok) { |
| 137 | g_scapy_error_content.style.display = 'block'; |
| 138 | } |
| 139 | |
| 140 | let msg = ""; |
| 141 | if (dbus_pcap_ok) { |
| 142 | msg += 'dbus-pcap found, md5sum: ' + |
| 143 | md5File.sync('dbus-pcap'); |
| 144 | g_dbus_pcap_status_content.style.display = 'block'; |
| 145 | g_dbus_pcap_status_content.textContent = msg; |
| 146 | } |
| 147 | |
| 148 | if (dbus_pcap_ok && scapy_ok) { |
| 149 | g_welcome_screen_content.style.display = 'block'; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | function Init() { |
| 154 | console.log('[Init] Initialization'); |
| 155 | ipmi_timeline_view.Canvas = document.getElementById('my_canvas_ipmi'); |
| 156 | dbus_timeline_view.Canvas = document.getElementById('my_canvas_dbus'); |
| 157 | boost_asio_handler_timeline_view.Canvas = |
| 158 | document.getElementById('my_canvas_boost_asio_handler'); |
| 159 | |
| 160 | // Hide all canvases until the user loads files |
| 161 | ipmi_timeline_view.Canvas.style.display = 'none'; |
| 162 | dbus_timeline_view.Canvas.style.display = 'none'; |
| 163 | boost_asio_handler_timeline_view.Canvas.style.display = 'none'; |
| 164 | |
| 165 | let v1 = ipmi_timeline_view; |
| 166 | let v2 = dbus_timeline_view; |
| 167 | let v3 = boost_asio_handler_timeline_view; |
| 168 | |
| 169 | // Link views |
| 170 | v1.linked_views = [v2, v3]; |
| 171 | v2.linked_views = [v1, v3]; |
| 172 | v3.linked_views = [v1, v2]; |
| 173 | |
| 174 | // Set accent color |
| 175 | v1.AccentColor = 'rgba(0,224,224,0.5)'; |
| 176 | v2.AccentColor = 'rgba(0,128,0, 0.5)'; |
| 177 | v3.AccentColor = '#E22'; |
| 178 | |
| 179 | CheckDependencies(); |
Sui Chen | c403b03 | 2022-03-06 18:03:12 -0800 | [diff] [blame] | 180 | |
| 181 | DragElement(document.getElementById("highlighted_messages")); |
Sui Chen | b65280f | 2020-06-30 18:14:03 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | var g_WelcomeScreen = document.getElementById('welcome_screen'); |
| 185 | function HideWelcomeScreen() { |
| 186 | g_WelcomeScreen.style.display = 'none'; |
| 187 | } |
| 188 | |
| 189 | var g_Blocker = document.getElementById('blocker'); |
| 190 | var g_BlockerCaption = document.getElementById('blocker_caption'); |
| 191 | function HideBlocker() { |
| 192 | g_Blocker.style.display = 'none'; |
| 193 | } |
| 194 | function ShowBlocker(msg) { |
| 195 | g_Blocker.style.display = 'block'; |
| 196 | g_BlockerCaption.textContent = msg; |
| 197 | } |
| 198 | |
| 199 | var g_Navigation = document.getElementById('div_navi_and_replay'); |
| 200 | function ShowNavigation() { |
| 201 | g_Navigation.style.display = 'block'; |
| 202 | } |
| 203 | |
| 204 | function UpdateFileNamesString() { |
| 205 | let tmp = []; |
| 206 | if (ipmi_timeline_view.CurrentFileName != '') { |
| 207 | tmp.push('IPMI timeline: ' + ipmi_timeline_view.CurrentFileName) |
| 208 | } |
| 209 | if (dbus_timeline_view.CurrentFileName != '') { |
| 210 | tmp.push('DBus timeline: ' + dbus_timeline_view.CurrentFileName) |
| 211 | } |
| 212 | if (boost_asio_handler_timeline_view.CurrentFileName != '') { |
| 213 | tmp.push( |
| 214 | 'ASIO timeline: ' + boost_asio_handler_timeline_view.CurrentFileName); |
| 215 | } |
| 216 | let s = tmp.join('<br/>'); |
| 217 | document.getElementById('capture_info').innerHTML = s; |
| 218 | } |
| 219 | |
| 220 | var g_cb_debug_info = document.getElementById('cb_debuginfo'); |
| 221 | |
| 222 | |
| 223 | Init(); |