Last active
October 24, 2017 15:09
-
-
Save mmarchini/d17d217db2cee88bf5dfe0f0a715582b to your computer and use it in GitHub Desktop.
Node USDT example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import usdt module | |
const USDT = require("usdt"); | |
// Create a Provider, which we'll use to register probes | |
const provider = new USDT.USDTProvider("nodeProvider"); | |
// Register your first probe with two arguments by passing its types | |
const probe1 = provider.addProbe("firstProbe", "int", "char *"); | |
// Enable provider (needed to fire probes later) | |
provider.enable(); | |
let countdown = 10; | |
function waiter() { | |
console.log("Trying to fire probe..."); | |
if(countdown <= 0) { | |
console.log("Disable provider"); | |
provider.disable(); | |
} | |
// Try to fire probe | |
probe1.fire(function() { | |
// This function will only run if the probe was enabled by an external tool | |
console.log("Probe fired!"); | |
countdown = countdown - 1; | |
// Returning values will be passed as arguments to the probe | |
return [countdown, "My little string"]; | |
}); | |
} | |
setInterval(waiter, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment