* Handle packet containing file metadata to send to KM
(packet)
| 174 | * Handle packet containing file metadata to send to KM |
| 175 | */ |
| 176 | _sendFile (packet) { |
| 177 | const filePath = JSON.parse(JSON.stringify(packet.data.return.dump_file)) |
| 178 | let type = null |
| 179 | if (packet.data.return.heapdump) { |
| 180 | type = 'heapdump' |
| 181 | } else if (packet.data.return.heapprofile) { |
| 182 | type = 'heapprofile' |
| 183 | } else if (packet.data.return.cpuprofile) { |
| 184 | type = 'cpuprofile' |
| 185 | } else { |
| 186 | return debug(`Invalid profiling packet: ${JSON.stringify(packet)}`) |
| 187 | } |
| 188 | debug('Send file for %s', type) |
| 189 | |
| 190 | packet = { |
| 191 | pm_id: packet.process.pm_id, |
| 192 | name: packet.process.name, |
| 193 | server_name: this.opts.MACHINE_NAME, |
| 194 | public_key: this.opts.PUBLIC_KEY, |
| 195 | type: type |
| 196 | } |
| 197 | packet[type] = true |
| 198 | |
| 199 | fs.readFile(filePath, (err, data) => { |
| 200 | if (err) return debug(err) |
| 201 | fs.unlink(filePath, debug) |
| 202 | packet.data = data.toString('utf-8') |
| 203 | return this.transport.send('profiling', packet) |
| 204 | }) |
| 205 | } |
| 206 | } |
no test coverage detected