Skip to content

Commit

Permalink
Add support for taking heap dumps
Browse files Browse the repository at this point in the history
This change adds a SIGUSR2 handler to write v8 heap dumps to the /tmp/
directory, in an effort to collect data to investigate #20.
  • Loading branch information
thenewwazoo committed Feb 6, 2022
1 parent 97ac63c commit c101d68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Lutron Caseta LEAP",
"name": "homebridge-lutron-caseta-leap",
"version": "2.2.2",
"version": "2.2.3",
"description": "Support for the Lutron Caseta Smart Bridge 2 (non-pro)",
"license": "Apache-2.0",
"repository": {
Expand Down
13 changes: 13 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { SerenaTiltOnlyWoodBlinds } from './SerenaTiltOnlyWoodBlinds';
import { PicoRemote } from './PicoRemote';
import { BridgeManager } from './BridgeManager';

import fs from 'fs';
import v8 from 'v8';
import process from 'process';

interface PlatformEvents {
unsolicited: (response: Response) => void;
}
Expand Down Expand Up @@ -64,6 +68,15 @@ export class LutronCasetaLeap
});
});

process.on('SIGUSR2', () => {
const fileName = `/tmp/lutron.${Date.now()}.heapsnapshot`;
this.log.warn(`Got request to dump heap. Dumping to ${fileName}`);
const snapshotStream = v8.getHeapSnapshot();
const fileStream = fs.createWriteStream(fileName);
snapshotStream.pipe(fileStream);
this.log.info(`Heap dump to ${fileName} finished.`);
});

log.info('LutronCasetaLeap plugin finished early initialization');
}

Expand Down

0 comments on commit c101d68

Please sign in to comment.