-
Notifications
You must be signed in to change notification settings - Fork 169
Add the devhub command: Gather metrics and upload them to a devhub database #3376
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| [alias] | ||
| uniffi-bindgen = ["run", "--package", "uniffi-bindgen", "--"] | ||
| benchmark = ["bench", "--manifest-path", "glean-core/benchmark/Cargo.toml"] | ||
| devhub = ["run", "--manifest-path", "tools/devhub/Cargo.toml", "--"] |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [workspace] | ||
| # Its own workspace to keep its dependencies separate | ||
|
|
||
| [package] | ||
| name = "devhub" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| serde = { version = "1.0", features = ["derive", "serde_derive"] } | ||
| serde_json = "1.0.145" | ||
| xflags = "0.3.2" | ||
| xshell = "0.2.7" |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Glean Devhub | ||
|
|
||
| Collect different metrics from the Glean SDK build and publish them. | ||
| Results will be displayed on <https://mozilla.github.io/glean/devhub>. | ||
|
|
||
| * This script is run by the CI infrastructure on every merge to `main`. | ||
| * It collects a set of "metrics", where a "metric" can be anything that can be measured with a single numeric value. | ||
| * The results of all measurements are serialized as a single JSON object. | ||
| * The key part: this JSON is then stored in a "distributed database" for our visualization | ||
| front-end to pick up. This "database" is just a newline-delimited JSON file in a Git repository. | ||
|
|
||
| To generate a `DEVHUBDB_TOKEN` (used on CI to publish to the database repository): | ||
|
|
||
| 1. Go to <https://github.com/settings/personal-access-tokens/new> | ||
| 2. Fill out token name (e.g. "Glean CI devhubdb token"). | ||
| 3. Resource owner: "mozilla" | ||
| 4. Expiry: "366 days" (maximum available) | ||
| 5. Repository access: "Only select repositories" | ||
| 6. Select repositories: "mozilla/glean-devhubdb" | ||
| 7. Add permissions: "Metadata" | ||
| 8. Add permissions: "Contents"; Access: "Read and write". | ||
| 9. "Generate token". | ||
| 10. (Copy token.) | ||
|
|
||
| To update token in Glean CI: | ||
|
|
||
| 1. <https://github.com/mozilla/glean/settings/environments> | ||
| 2. Click "production". | ||
| 3. Environment Secrets > Edit `DEVHUBDB_TOKEN` | ||
| 4. Paste token; "Update secret" | ||
|
|
||
| ## References | ||
|
|
||
| This code is based on ideas from: | ||
|
|
||
| * [TigerBeetle's devhub](https://github.com/tigerbeetle/tigerbeetle/blob/b6d541562290f23c10760ea20b559cf21b9010b0/src/scripts/devhub.zig) | ||
| * [PerfHerder](https://treeherder.mozilla.org/perfherder/), | ||
| and specifically [`PerfStats`](https://firefox-source-docs.mozilla.org/performance/perfstats.html) and [`MozGTestBench`](https://firefox-source-docs.mozilla.org/gtest/index.html#mozgtestbench) |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| use serde::Deserialize; | ||
| use xshell::{Shell, cmd}; | ||
|
|
||
| use super::{Metric, MetricRecorder, Result}; | ||
|
|
||
| /// Extract the listed metrics out from all benchmarks, grouped by the benchmark name. | ||
| const JQ_SCRIPT: &str = r#" | ||
| .profiles[0].summaries.parts[0].metrics_summary.Cachegrind as $cachegrind | ||
| | .function_name + " " + .details as $name | ||
| | [ "Ir", "EstimatedCycles", "TotalRW", "L1hits", "LLhits", "RamHits" ] as $keys | ||
| | $keys | ||
| | map({ | ||
| name: $name + " -- " + ., | ||
| value: $cachegrind[.].metrics.Both[0].Int | ||
| }) | ||
| "#; | ||
|
|
||
| /// Parse Gungraun benchmark results | ||
| /// | ||
| /// Expects a `gungraun-output.json` file in the current directory. | ||
| pub struct Benchmark; | ||
|
|
||
| impl MetricRecorder for Benchmark { | ||
| fn name(&self) -> &'static str { | ||
| "benchmark" | ||
| } | ||
|
|
||
| fn description(&self) -> &'static str { | ||
| "Gungraun Benchmark Results" | ||
| } | ||
|
|
||
| fn record(&self, sh: &Shell) -> Result<Vec<Metric>> { | ||
| let temp = sh.create_temp_dir()?; | ||
|
|
||
| let jq_script_path = temp.path().join("transform-gungraun.jq"); | ||
| sh.write_file(&jq_script_path, JQ_SCRIPT)?; | ||
|
|
||
| let input = sh.current_dir().join("gungraun-output.json"); | ||
|
|
||
| let mut metrics = Vec::new(); | ||
|
|
||
| let benchmarks = cmd!(sh, "jq -cf {jq_script_path} {input}").read()?; | ||
| let benchmarks = benchmarks.lines(); | ||
| for line in benchmarks { | ||
| let bench: Vec<Bench> = serde_json::from_str(line)?; | ||
|
|
||
| for b in bench { | ||
| metrics.push(Metric { | ||
| name: b.name, | ||
| value: b.value, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| Ok(metrics) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct Bench { | ||
| name: String, | ||
| value: u64, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.