Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DTrace scripts to Nexus zone #7244

Merged
merged 6 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ source.paths = [
{ from = "smf/nexus/{{rack-topology}}", to = "/var/svc/manifest/site/nexus" },
{ from = "out/console-assets", to = "/var/nexus/static" },
{ from = "schema/crdb", to = "/var/nexus/schema/crdb" },
{ from = "tools/dtrace/nexus", to = "/opt/oxide/dtrace/nexus" },
]
output.type = "zone"
setup_hint = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ diesel_db$target:::query-done
query[this->conn_id] = NULL;
}

tick-5s
tick-10s
{
printf("\n%Y\n", walltimestamp);
trunc(@, 5);
Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions tools/dtrace/nexus/trace-transactions.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/sbin/dtrace -qs

/* Trace all transactions to the control plane database with their latency */

dtrace:::BEGIN
{
printf("Tracing all database transactions for nexus PID %d, use Ctrl-C to exit\n", $target);
}

/*
* Record the start and number of statements for each transaction.
*
* Note that we're using the Nexus-provided transaction start / done probes.
* This lets us associate the other data we might collect (number of statements,
* ustacks, etc) with the Nexus code itself. Although there are transaction
* start / done probes in `diesel-dtrace`, the existing way we run transactions
* with `async-bb8-diesel` involves spawning a future to run the transactions on
* a blocking thread-pool. That spawning makes it impossible to associate the
* context in which the `diesel-dtrace` probes fire with the Nexus code that
* actually spawned the transaction itself.
*/
nexus_db_queries$target:::transaction-start
{
this->key = copyinstr(arg0);
transaction_names[this->key] = copyinstr(arg1);
ts[this->key] = timestamp;
n_statements[this->key] = 0;
printf(
"Started transaction '%s' on conn %s\n",
transaction_names[this->key],
json(this->key, "ok")
);
}

/*
* When a query runs in the context of a transaction (on the same connection),
* bump the statement counter.
*/
diesel_db$target:::query-start
/ts[copyinstr(arg1)]/
{
n_statements[copyinstr(arg1)] += 1
}

/*
* As transactions complete, print the number of statements we ran and the
* duration.
*/
nexus_db_queries$target:::transaction-done
/ts[copyinstr(arg0)]/
{
this->key = copyinstr(arg0);
bnaecker marked this conversation as resolved.
Show resolved Hide resolved
this->conn_id = json(this->key, "ok");
this->latency = (timestamp - ts[this->key]) / 1000;
this->n_statements = n_statements[this->key];
printf(
"%s %d statement(s) in transaction '%s' on connection %s (%d us)\n",
arg2 ? "COMMIT" : "ROLLBACK",
n_statements[this->key],
transaction_names[this->key],
this->conn_id,
this->latency
);
ts[this->key] = 0;
n_statements[this->key] = 0;
transaction_names[this->key] = 0;
}
2 changes: 2 additions & 0 deletions workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ generic-array = { version = "0.14.7", default-features = false, features = ["mor
getrandom = { version = "0.2.15", default-features = false, features = ["js", "rdrand", "std"] }
group = { version = "0.13.0", default-features = false, features = ["alloc"] }
hashbrown = { version = "0.15.1" }
heck = { version = "0.4.1" }
hex = { version = "0.4.3", features = ["serde"] }
hickory-proto = { version = "0.24.1", features = ["text-parsing"] }
hmac = { version = "0.12.1", default-features = false, features = ["reset"] }
Expand Down Expand Up @@ -182,6 +183,7 @@ generic-array = { version = "0.14.7", default-features = false, features = ["mor
getrandom = { version = "0.2.15", default-features = false, features = ["js", "rdrand", "std"] }
group = { version = "0.13.0", default-features = false, features = ["alloc"] }
hashbrown = { version = "0.15.1" }
heck = { version = "0.4.1" }
hex = { version = "0.4.3", features = ["serde"] }
hickory-proto = { version = "0.24.1", features = ["text-parsing"] }
hmac = { version = "0.12.1", default-features = false, features = ["reset"] }
Expand Down
Loading