├── .github
├── CODEOWNERS
├── dependabot.yml
├── renovate.json5
└── workflows
│ └── main.yml
├── .gitignore
├── .gitmodules
├── AUTHORS.md
├── CONTRIBUTING.md
├── Cargo.lock
├── Cargo.toml
├── LICENSE.txt
├── Makefile
├── NOTICE.txt
├── README.md
├── assets
├── icon.png
├── screenshot.png
├── screenshot1.png
└── screenshot2.png
├── build.rs
├── flake.lock
├── flake.nix
├── renovate.json
├── rustfmt.toml
└── src
├── collector
├── mod.rs
└── otlp
│ ├── mod.rs
│ ├── pb.rs
│ └── service.rs
├── log.rs
├── main.rs
├── storage
├── dbtypes.rs
├── errorspec.rs
├── metricspec.rs
├── mod.rs
├── notify.rs
├── rkyvtree.rs
├── symdb
│ └── mod.rs
├── table.rs
└── tables
│ ├── executables.rs
│ ├── metrics.rs
│ ├── mod.rs
│ ├── stackframes.rs
│ ├── stacktraces.rs
│ └── traceevents.rs
├── symbolizer
└── mod.rs
└── ui
├── add-data.md
├── app.rs
├── cached.rs
├── mod.rs
├── tabs
├── dbstats.rs
├── executables.rs
├── flamegraph.rs
├── grpclog.rs
├── log.rs
├── metrics.rs
├── mod.rs
├── top_funcs.rs
└── trace_freq.rs
├── timeaxis.rs
└── util.rs
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @elastic/ingest-otel-data
2 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | # GitHub actions
4 | - package-ecosystem: "github-actions"
5 | directory: ".github/workflows"
6 | schedule:
7 | interval: "weekly"
8 | groups:
9 | github-actions:
10 | patterns:
11 | - "*"
12 |
--------------------------------------------------------------------------------
/.github/renovate.json5:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "config:best-practices",
5 | "helpers:pinGitHubActionDigestsToSemver"
6 | ],
7 | "packageRules": [
8 | {
9 | "groupName": "GitHub Actions",
10 | "matchManagers": ["github-actions"],
11 | "schedule": ["before 8am every weekday"],
12 | "automerge": true
13 | },
14 | {
15 | "groupName": "Rust dependencies",
16 | "matchManagers": ["cargo"],
17 | "schedule": ["before 8am every weekday"],
18 | "automerge": true
19 | }
20 | ],
21 | "labels": [
22 | "dependencies"
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ "**" ]
8 | schedule:
9 | # GitHub deletes caches after not being used for 7 days. An uncached build
10 | # takes about 30x longer than one with caches. Hence: make sure that caches
11 | # for the main branch never fall out of LRU.
12 | - cron: '0 0 */6 * *'
13 |
14 | env:
15 | APPIMAGE_BUNDLER: github:ralismark/nix-appimage?rev=17dd6001ec228ea0b8505d6904fc5796d3de5012
16 |
17 | permissions:
18 | contents: read
19 |
20 | jobs:
21 | nix-build:
22 | name: Build with Nix
23 | runs-on: ${{ matrix.os }}
24 |
25 | strategy:
26 | matrix:
27 | # Backing architectures based on information from
28 | # https://github.com/actions/runner-images/
29 | #
30 | # ubuntu-22.04 - amd64
31 | # macos-14-large - amd64
32 | # macos-14-xlarge - arm64
33 | os: [ ubuntu-22.04, macos-14-large, macos-14-xlarge ]
34 |
35 | steps:
36 | - name: Get token
37 | id: get_token
38 | uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
39 | with:
40 | app_id: ${{ secrets.ELASTIC_OBSERVABILITY_APP_ID }}
41 | private_key: ${{ secrets.ELASTIC_OBSERVABILITY_APP_PEM }}
42 | permissions: >-
43 | {
44 | "contents": "read"
45 | }
46 | repositories: >-
47 | ["devfiler"]
48 |
49 | - name: Checkout code
50 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
51 | with:
52 | token: ${{ steps.get_token.outputs.token }}
53 | submodules: true
54 |
55 | - name: Install Nix
56 | uses: cachix/install-nix-action@f0fe604f8a612776892427721526b4c7cfb23aba # v31
57 | with:
58 | install_url: https://releases.nixos.org/nix/nix-2.16.2/install
59 |
60 | - name: Execute checks
61 | run: nix flake check -L '.?submodules=1#'
62 | - name: Build
63 | # Use 8 jobs to force more concurrency with crate download jobs.
64 | run: nix build -L -j8 '.?submodules=1#'
65 |
66 | # Linux only
67 | - name: Build AppImage (Linux x86_64 only)
68 | if: runner.os == 'Linux'
69 | run: nix bundle --system x86_64-linux --inputs-from . --bundler $APPIMAGE_BUNDLER -L '.?submodules=1#appImageWrapper'
70 |
71 | # macOS only
72 | - name: Build application bundle (macOS only)
73 | if: runner.os == 'macOS'
74 | run: nix build -L '.?submodules=1#macAppZip'
75 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | .idea
3 | result
4 | *.AppImage
5 | .DS_Store
6 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "opentelemetry-proto"]
2 | path = opentelemetry-proto
3 | url = https://github.com/open-telemetry/opentelemetry-proto.git
4 | [submodule "opentelemetry-ebpf-profiler"]
5 | path = opentelemetry-ebpf-profiler
6 | url = https://github.com/open-telemetry/opentelemetry-ebpf-profiler.git
7 |
--------------------------------------------------------------------------------
/AUTHORS.md:
--------------------------------------------------------------------------------
1 | ## Pre-OSS Elastic contributors
2 |
3 | - [@athre0z](https://github.com/athre0z)
4 | - [@florianl](https://github.com/florianl)
5 | - [@christos68k](https://github.com/christos68k)
6 | - [@rockdaboot](https://github.com/rockdaboot)
7 | - [@jbcrail](https://github.com/jbcrail)
8 | - [@girodav](https://github.com/girodav)
9 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing to Devfiler
2 | ===========================
3 |
4 | Devfiler is a free and open project and we love to receive contributions from our community — you!
5 |
6 | In order for your contributions to be accepted, please make sure you have signed our
7 | [Contributor License Agreement](https://www.elastic.co/contributor-agreement/). We are not asking you to assign copyright to us, but to give us the right to distribute your code without restriction. We ask this of all contributors in order to assure our users of the origin and continuing existence of the code. You only need to sign the CLA once.
8 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "devfiler"
3 | version = "0.14.0"
4 | edition = "2021"
5 | license = "Apache-2.0"
6 |
7 | [profile.dev]
8 | opt-level = 1
9 |
10 | [profile.release]
11 | opt-level = 3
12 | panic = "abort"
13 | debug = 1
14 |
15 | [profile.release-lto]
16 | inherits = "release"
17 | lto = "thin"
18 | codegen-units = 1
19 | strip = true
20 |
21 | [features]
22 | default = ["render-opengl", "automagic-symbols", "allow-dev-mode"]
23 |
24 | # Enable the OpenGL renderer backend.
25 | render-opengl = ["eframe/glow"]
26 | # Enable the WebGPU (Metal, Vulkan) renderer backend.
27 | render-wgpu = ["eframe/wgpu"]
28 | # Enable automagic symbolization from global indexing infra.
29 | automagic-symbols = []
30 | # Allow entering UP developer mode by double-clicking the logo.
31 | allow-dev-mode = []
32 | # Enable UP developer mode by default.
33 | default-dev-mode = ["allow-dev-mode"]
34 |
35 | [dependencies]
36 | symblib = { version = "*", path = "./opentelemetry-ebpf-profiler/rust-crates/symblib" }
37 | anyhow = "1.0.71"
38 | smallvec = "1.11.1"
39 | arc-swap = "1.6.0"
40 | base64 = "0.22.0"
41 | egui = "0.29.1"
42 | egui_plot = "0.29.0"
43 | egui_extras = { version = "0.29.1", features = ["image"] }
44 | egui_commonmark = "0.18.0"
45 | egui-phosphor = "0.7.3"
46 | fallible-iterator = "0.3.0"
47 | chrono = "0.4.31"
48 | indexmap = "2.1.0"
49 | itertools = "0.14.0"
50 | lazy_static = "1.4.0"
51 | home = "0.5"
52 | prost = "0.12.1"
53 | reqwest = { version = "0.12.0", features = ["json"] }
54 | rand = "0.9.0"
55 | rkyv = { version = "0.7.42", features = ["strict"] }
56 | serde = { version = "1.0.193", features = ["derive"] }
57 | serde_json = "1.0.108"
58 | tikv-jemallocator = "0.5.4"
59 | tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"] }
60 | tonic = { version = "0.11.0", features = ["gzip"] }
61 | tracing = "0.1.37"
62 | tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
63 | zstd = "0.13.0"
64 | lru = "0.14.0"
65 | nohash-hasher = "0.2.0"
66 | memmap2 = "0.9.4"
67 | xxhash-rust = { version = "0.8.10", features = ["xxh3"] }
68 | hashbrown = "0.15.2"
69 | idna = "1.0.3"
70 |
71 | [dependencies.rocksdb]
72 | version = "0.22.0"
73 | default-features = false
74 | features = ["zstd", "jemalloc"]
75 |
76 | [dependencies.eframe]
77 | version = "0.29.1"
78 | default-features = false
79 | features = ["default_fonts", "x11"]
80 |
81 | [build-dependencies]
82 | tonic-build = "0.11.0"
83 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: all release debug init test clean
2 |
3 | CARGO = cargo
4 |
5 | # Set V=1 for verbose output
6 | ifeq ($(V),1)
7 | Q =
8 | else
9 | Q = @
10 | endif
11 |
12 | all: release
13 |
14 | release:
15 | $(Q)$(CARGO) build --release
16 |
17 | debug:
18 | $(Q)$(CARGO) build --debug
19 |
20 | init:
21 | $(Q)git submodule init
22 | $(Q)git submodule update
23 |
24 | test:
25 | $(Q)$(CARGO) test
26 |
27 | clean:
28 | $(Q)$(CARGO) clean
29 |
30 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | devfiler
2 | Copyright 2025 Elasticsearch B.V.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 |
16 | ---
17 | This product includes code that is based on rkyv serializable interval tree,
18 | which was available under a "MIT" license.
19 |
20 | MIT License
21 | Copyright (c) 2018 main()
22 |
23 | Permission is hereby granted, free of charge, to any person obtaining a copy
24 | of this software and associated documentation files (the "Software"), to deal
25 | in the Software without restriction, including without limitation the rights
26 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 | copies of the Software, and to permit persons to whom the Software is
28 | furnished to do so, subject to the following conditions:
29 |
30 | The above copyright notice and this permission notice shall be included in all
31 | copies or substantial portions of the Software.
32 |
33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 | SOFTWARE.
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | devfiler
2 | =========
3 |
4 | devfiler reimplements the whole collection, data storage, symbolization, and UI portion of
5 | [OTel eBPF Profiler] in a desktop application. This essentially allows developers to start
6 | using the profiling agent in a matter of seconds without having to spin up a whole Elastic
7 | deployment first.
8 |
9 | [OTel eBPF Profiler]: https://github.com/open-telemetry/opentelemetry-ebpf-profiler/
10 |
11 | devfiler currently supports running on macOS and Linux. Note that this doesn't mean that this
12 | application can profile macOS applications: the [OTel eBPF Profiler] still needs to run on a Linux
13 | machine, but the UI can be used on macOS.
14 |
15 | > [!NOTE]
16 | >
17 | > This is currently **not** a supported product. It started out as [@athre0z]'s personal
18 | > project and was later transferred to the Elastic GitHub account because some people in
19 | > the team liked the idea of having it to speed up some development workflows and
20 | > prototyping. We're now releasing it under Apache-2.0 to help with OTLP Profiling
21 | > development.
22 |
23 | [@athre0z]: https://github.com/athre0z
24 |
25 |
26 |
27 |
28 |
29 | ## Build
30 |
31 | ### Nix
32 |
33 | The primary build system is currently the [Nix] package manager. Once Nix is
34 | installed on the system, devfiler can be built with the following command:
35 |
36 | ```
37 | nix --experimental-features 'flakes nix-command' build '.?submodules=1#'
38 | ```
39 |
40 | The executable is placed in the Nix store and a symlink is created in the root of this directory.
41 | You can then run devfiler using:
42 |
43 | ```
44 | result/bin/devfiler
45 | ```
46 |
47 | Alternatively you can simply ask Nix to both build and run it for you:
48 |
49 | ```
50 | nix --experimental-features 'flakes nix-command' run '.?submodules=1#'
51 | ```
52 |
53 | If you are on Linux and run into OpenGL (glutin) errors, try the following instead:
54 |
55 | ```
56 | nix --experimental-features 'flakes nix-command' run '.?submodules=1#devfilerDistroGL'
57 | ```
58 |
59 | [Nix]: https://nixos.org/download
60 |
61 | The need to always pass the `--experimental-features` argument can be circumvented by putting
62 |
63 | ```
64 | experimental-features = nix-command flakes
65 | ```
66 |
67 | into `~/.config/nix/nix.conf`.
68 |
69 | ### Cargo
70 |
71 | Alternatively it's also possible to build devfiler with just plain cargo. This currently doesn't
72 | allow generating a proper application bundle for macOS, but it's perfectly sufficient for
73 | development and local use. Cargo is typically best installed via [rustup], but using `cargo` and
74 | `rustc` from your distribution repositories might work as well if it is recent enough.
75 |
76 | [rustup]: https://rustup.rs/
77 |
78 | Additionally, make sure that `g++` (or `clang`), `libclang` and `protoc` are available on
79 | the system. The following should do the job for Debian and Ubuntu. The packages should also
80 | be available in the repositories of other distributions and also from MacPorts/Brew, but
81 | names may vary.
82 |
83 | ```
84 | sudo apt install g++ libclang-dev protobuf-compiler libprotobuf-dev cmake
85 | ```
86 |
87 | devfiler can then be built using:
88 |
89 | ```
90 | # Update submodules only after cloning the repository or when the submodules change.
91 | git submodule update --init --recursive
92 |
93 | cargo build --release
94 | ```
95 |
96 | The executable is placed in `target/release/devfiler`.
97 |
98 | ## Adding traces
99 |
100 | devfiler is listening for profiling agent connections on `0.0.0.0:11000`. To ingest traces,
101 | use a recent version of the OTel eBPF profiler and then run it like this:
102 |
103 | ```
104 | sudo ./ebpf-profiler -collection-agent=127.0.0.1:11000 -disable-tls
105 | ```
106 |
107 | ### Profiling on remote hosts
108 |
109 | A common use-case is to ssh into and run the profiling agent on a remote machine. The easiest
110 | way to set up the connection in this case is with a [ssh reverse tunnel]. Simply run devfiler
111 | locally and then connect to your remote machine like this:
112 |
113 | ```
114 | ssh -R11000:localhost:11000 someuser@somehost
115 | ```
116 |
117 | This will cause sshd to listen on port `11000` on the remote machine, forwarding all connections
118 | to port `11000` on the local machine. When you then run the profiling agent on the remote and point
119 | it to `127.0.0.1:11000`, the connection will be forwarded to your local devfiler.
120 |
121 | [ssh reverse tunnel]: https://unix.stackexchange.com/questions/46235/how-does-reverse-ssh-tunneling-work
122 |
123 | ## Developer mode
124 |
125 | Some of the more internal tabs that are only relevant to developers are hidden by default. You can
126 | unveil them with a double click on the "devfiler" text in the top left.
127 |
128 | ## Releases
129 |
130 |
131 | Creating release artifacts locally
132 |
133 | Update `version` in `Cargo.toml` for the package to the appropriate release version number
134 |
135 | ```
136 | # On a linux machine, architecture doesn't matter as long as qemu binfmt is installed:
137 | nix bundle --system aarch64-linux --inputs-from . --bundler 'github:ralismark/nix-appimage' '.?submodules=1#appImageWrapper' -L
138 | nix bundle --system x86_64-linux --inputs-from . --bundler 'github:ralismark/nix-appimage' '.?submodules=1#appImageWrapper' -L
139 | # Resulting appimages are symlinked into CWD.
140 |
141 | # On a ARM64 mac w/ Rosetta installed:
142 | nix build -L '.?submodules=1#packages.aarch64-darwin.macAppZip' -j20
143 | cp result/devfiler.zip devfiler-apple-silicon-mac.zip
144 | nix build -L '.?submodules=1#packages.x86_64-darwin.macAppZip' -j20
145 | cp result/devfiler.zip devfiler-intel-mac.zip
146 | ```
147 |
148 |
149 |
150 | > [!NOTE]
151 | >
152 | > Binary releases are covered by multiple licenses (stemming from compiling and
153 | > linking third-party library dependencies) and the user is responsible for reviewing
154 | > these licenses and ensuring that license terms (e.g. redistribution and copyright
155 | > attribution) are met.
156 | >
157 | > Elastic does not provide devfiler binary releases.
158 |
--------------------------------------------------------------------------------
/assets/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elastic/devfiler/297fe19e9ad0aa7bed93f7ffb97e2e6d09d5ffb2/assets/icon.png
--------------------------------------------------------------------------------
/assets/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elastic/devfiler/297fe19e9ad0aa7bed93f7ffb97e2e6d09d5ffb2/assets/screenshot.png
--------------------------------------------------------------------------------
/assets/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elastic/devfiler/297fe19e9ad0aa7bed93f7ffb97e2e6d09d5ffb2/assets/screenshot1.png
--------------------------------------------------------------------------------
/assets/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elastic/devfiler/297fe19e9ad0aa7bed93f7ffb97e2e6d09d5ffb2/assets/screenshot2.png
--------------------------------------------------------------------------------
/build.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | static PROTOS: &[&str] =
19 | &["opentelemetry-proto/opentelemetry/proto/collector/profiles/v1development/profiles_service.proto"];
20 |
21 | static INCLUDE_DIRS: &[&str] = &["opentelemetry-proto"];
22 |
23 | fn main() {
24 | tonic_build::configure()
25 | .type_attribute(".", "#[derive(::serde::Serialize)]")
26 | .compile(PROTOS, INCLUDE_DIRS)
27 | .unwrap();
28 | }
29 |
--------------------------------------------------------------------------------
/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "crane": {
4 | "inputs": {
5 | "nixpkgs": [
6 | "nixpkgs"
7 | ]
8 | },
9 | "locked": {
10 | "lastModified": 1707461758,
11 | "narHash": "sha256-VaqINICYEtVKF0X+chdNtXcNp6poZr385v6AG7j0ybM=",
12 | "owner": "ipetkov",
13 | "repo": "crane",
14 | "rev": "505976eaeac289fe41d074bee37006ac094636bb",
15 | "type": "github"
16 | },
17 | "original": {
18 | "owner": "ipetkov",
19 | "repo": "crane",
20 | "type": "github"
21 | }
22 | },
23 | "flake-utils": {
24 | "inputs": {
25 | "systems": "systems"
26 | },
27 | "locked": {
28 | "lastModified": 1705309234,
29 | "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
30 | "owner": "numtide",
31 | "repo": "flake-utils",
32 | "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
33 | "type": "github"
34 | },
35 | "original": {
36 | "owner": "numtide",
37 | "repo": "flake-utils",
38 | "type": "github"
39 | }
40 | },
41 | "nixpkgs": {
42 | "locked": {
43 | "lastModified": 1735563628,
44 | "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=",
45 | "owner": "NixOS",
46 | "repo": "nixpkgs",
47 | "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798",
48 | "type": "github"
49 | },
50 | "original": {
51 | "owner": "NixOS",
52 | "ref": "nixos-24.05",
53 | "repo": "nixpkgs",
54 | "type": "github"
55 | }
56 | },
57 | "root": {
58 | "inputs": {
59 | "crane": "crane",
60 | "flake-utils": "flake-utils",
61 | "nixpkgs": "nixpkgs"
62 | }
63 | },
64 | "systems": {
65 | "locked": {
66 | "lastModified": 1681028828,
67 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
68 | "owner": "nix-systems",
69 | "repo": "default",
70 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
71 | "type": "github"
72 | },
73 | "original": {
74 | "owner": "nix-systems",
75 | "repo": "default",
76 | "type": "github"
77 | }
78 | }
79 | },
80 | "root": "root",
81 | "version": 7
82 | }
83 |
--------------------------------------------------------------------------------
/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | description = "devfiler: universal profiling as a desktop app";
3 |
4 | inputs = {
5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
6 | flake-utils.url = "github:numtide/flake-utils";
7 | crane.url = "github:ipetkov/crane";
8 | crane.inputs.nixpkgs.follows = "nixpkgs";
9 | };
10 |
11 | outputs = { crane, flake-utils, nixpkgs, ... }:
12 | flake-utils.lib.eachSystem [
13 | "aarch64-linux"
14 | "x86_64-linux"
15 | "aarch64-darwin"
16 | "x86_64-darwin"
17 | ]
18 | (system:
19 | let
20 | pkgs = import nixpkgs { inherit system; };
21 | llvm = pkgs.llvmPackages_16;
22 | stdenv = llvm.stdenv;
23 | lib = pkgs.lib;
24 | isLinux = stdenv.isLinux;
25 | isDarwin = stdenv.isDarwin;
26 | craneLib = (crane.mkLib pkgs);
27 |
28 | # Filter source tree to avoid unnecessary rebuilds.
29 | includedSuffixes = [
30 | ".proto"
31 | "metrics.json"
32 | "errors.json"
33 | "icon.png"
34 | "add-data.md"
35 | "README.md"
36 | ];
37 | isBuildInput = p: lib.any (x: lib.hasSuffix x p) includedSuffixes;
38 | devfilerSources = lib.cleanSourceWith {
39 | src = lib.cleanSource (craneLib.path ./.);
40 | filter = (o: t: (craneLib.filterCargoSources o t) || (isBuildInput o));
41 | };
42 | assets = builtins.path {
43 | path = ./assets;
44 | name = "devfiler-assets";
45 | };
46 |
47 | # RocksDB library to be used.
48 | rocksdb = stdenv.mkDerivation rec {
49 | name = "rocksdb";
50 | version = "8.10.0"; # must match what the Rust bindings expect!
51 | src = pkgs.fetchFromGitHub {
52 | owner = "facebook";
53 | repo = "rocksdb";
54 | rev = "v${version}";
55 | hash = "sha256-KGsYDBc1fz/90YYNGwlZ0LUKXYsP1zyhP29TnRQwgjQ=";
56 | };
57 | nativeBuildInputs = with pkgs; [ cmake ninja ];
58 | propagatedBuildInputs = with pkgs; [ zstd ];
59 | env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-faligned-allocation";
60 | cmakeFlags = [
61 | "-DPORTABLE=1" # suppress -march=native
62 | "-DWITH_ZSTD=ON"
63 | #"-DWITH_JEMALLOC=ON"
64 | "-DWITH_TOOLS=OFF"
65 | "-DWITH_CORE_TOOLS=OFF"
66 | "-DWITH_BENCHMARK_TOOLS=OFF"
67 | "-DWITH_TESTS=OFF"
68 | "-DWITH_JNI=OFF"
69 | "-DWITH_GFLAGS=OFF"
70 | "-DROCKSDB_BUILD_SHARED=OFF"
71 | "-DFAIL_ON_WARNINGS=OFF"
72 | ];
73 | dontFixup = true;
74 | };
75 |
76 | # On Linux egui dynamically links against X11 and OpenGL. The libraries
77 | # listed below are injected into the RPATH to ensure that our executable
78 | # finds them at runtime.
79 | linuxDynamicLibs = lib.makeLibraryPath (with pkgs; with xorg; [
80 | libGL
81 | libX11
82 | libxkbcommon
83 | libXcursor
84 | libXrandr
85 | libXi
86 | ]);
87 |
88 | buildDevfiler =
89 | { profile ? "release"
90 | , extraFeatures ? [ "automagic-symbols" "allow-dev-mode" ]
91 | }: craneLib.buildPackage {
92 | inherit stdenv;
93 | strictDeps = true;
94 | src = devfilerSources;
95 | doCheck = false;
96 | dontStrip = true;
97 | dontPatchELF = true; # we do this ourselves
98 | meta.mainProgram = "devfiler";
99 |
100 | buildInputs = [
101 | rocksdb
102 | ] ++ lib.optional isLinux [
103 | pkgs.libcxx
104 | pkgs.openssl
105 | pkgs.gcc-unwrapped
106 | ] ++ lib.optional isDarwin [
107 | pkgs.libiconv
108 | pkgs.darwin.apple_sdk.frameworks.CoreServices
109 | pkgs.darwin.apple_sdk.frameworks.AppKit
110 | ];
111 |
112 | nativeBuildInputs = with pkgs; [ cmake protobuf copyDesktopItems ]
113 | ++ lib.optional isDarwin desktopToDarwinBundle
114 | ++ lib.optional isLinux pkg-config;
115 |
116 | desktopItems = pkgs.makeDesktopItem {
117 | name = "devfiler";
118 | exec = "devfiler";
119 | comment = "Elastic Universal Profiling desktop app";
120 | desktopName = "devfiler";
121 | icon = "devfiler";
122 | };
123 |
124 | cargoExtraArgs =
125 | let
126 | # wgpu renderer is generally preferable because it uses Metal (macOS)
127 | # or Vulkan (Linux). Unfortuantely it hard-freezes some people's Linux
128 | # kernel when running on Intel drivers. Only use it on macOS for now.
129 | renderer = if isDarwin then "render-wgpu" else "render-opengl";
130 | features = [ renderer ] ++ extraFeatures;
131 | merged = lib.concatStringsSep "," features;
132 | in
133 | "--no-default-features --features ${merged}";
134 |
135 | env = {
136 | # Use our custom build of RocksDB (instead of letting cargo build it).
137 | ROCKSDB_INCLUDE_DIR = "${rocksdb}/include";
138 | ROCKSDB_LIB_DIR = "${rocksdb}/lib";
139 | ROCKSDB_STATIC = "1";
140 |
141 | # libclang required by rocksdb-rs bindgen.
142 | LIBCLANG_PATH = llvm.libclang.lib + "/lib/";
143 |
144 | CARGO_PROFILE = profile;
145 |
146 | RUSTFLAGS = toString [
147 | # Mold speeds up the build by a few seconds.
148 | # It doesn't support macOS: only use it on Linux.
149 | (lib.optional isLinux "-Clink-arg=--ld-path=${pkgs.mold-wrapped}/bin/mold")
150 |
151 | # On Darwin, librocksdb-sys links C++ libraries in some weird
152 | # way that doesn't work with `buildInputs`. Link it manually ...
153 | (lib.optionals isDarwin [
154 | "-L${pkgs.libcxx}/lib"
155 | "-ldylib=c++"
156 | "-ldylib=c++abi"
157 | ])
158 | ];
159 | } // lib.optionalAttrs isLinux {
160 | PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
161 | };
162 |
163 | preInstall = ''
164 | install -Dm644 ${assets}/icon.png \
165 | $out/share/icons/hicolor/512x512/apps/devfiler.png
166 | '';
167 | postInstall = lib.optionalString isLinux ''
168 | patchelf --shrink-rpath $out/bin/devfiler
169 | patchelf --add-rpath ${linuxDynamicLibs} $out/bin/devfiler
170 | '';
171 |
172 | # On macOS, ship the required C++ runtime libs as part of
173 | # the application bundle that we are building.
174 | postFixup = lib.optionalString isDarwin ''
175 | ppp=$out/Applications/devfiler.app/Contents/MacOS/
176 | if [[ -d $ppp ]]; then # don't run in "deps" step
177 | mv $out/bin/devfiler $ppp
178 | cp ${pkgs.libcxx}/lib/libc++.1.0.dylib $ppp
179 | cp ${pkgs.libcxx}/lib/libc++abi.1.dylib $ppp
180 |
181 | # Make files writable
182 | chmod +w $ppp/devfiler
183 | chmod +w $ppp/libc++.1.0.dylib
184 | chmod +w $ppp/libc++abi.1.dylib
185 |
186 | # Fix the main executable
187 | install_name_tool \
188 | -change ${pkgs.libcxx}/lib/libc++.1.0.dylib \
189 | @executable_path/libc++.1.0.dylib \
190 | -change ${pkgs.libcxx}/lib/libc++abi.1.0.dylib \
191 | @executable_path/libc++abi.1.dylib \
192 | -change ${pkgs.libiconv}/lib/libiconv.dylib \
193 | /usr/lib/libiconv.2.dylib \
194 | $ppp/devfiler
195 |
196 | # Fix libc++.1.0.dylib's dependencies
197 | install_name_tool \
198 | -change ${pkgs.libcxx}/lib/libc++abi.1.dylib \
199 | @executable_path/libc++abi.1.dylib \
200 | $ppp/libc++.1.0.dylib
201 | fi
202 | '';
203 | };
204 |
205 | devfilerCheckRustfmt = craneLib.cargoFmt {
206 | src = devfilerSources;
207 | };
208 |
209 | macSystemName = {
210 | "aarch64-darwin" = "apple-silicon";
211 | "x86_64-darwin" = "intel-mac";
212 | }.${system} or (throw "unsupported mac system: ${system}");
213 |
214 | macAppZip = pkgs.runCommand "devfiler-mac-app" {
215 | nativeBuildInputs = [ pkgs.zip ];
216 | } ''
217 | # Copy and change permissions. Without this the app extracted from
218 | # the zip will be read-only and require extra steps to move around.
219 | cp -rL ${buildDevfiler {}}/Applications/devfiler.app .
220 | chmod -R u+w .
221 |
222 | install -d $out
223 | zip -r $out/devfiler-${macSystemName}.app.zip devfiler.app
224 | '';
225 |
226 | # Build the contents of our AppImage package.
227 | #
228 | # 1) We need to strip the Nix specific `linuxDynamicLibs` library paths
229 | # that contain X11 and OpenGL libraries. They won't work on regular
230 | # distributions because the corresponding user-mode graphics drivers
231 | # will be missing. We need to load the native distro libs for that.
232 | # 2) Nix's glibc is patched to ignore `/etc/ld.so.conf`. This is what
233 | # allows it to co-exist on regular distros and makes sure that Nix
234 | # executables don't accidentally load regular distro libs. However,
235 | # in the case of our AppImage, that works against us: egui loads
236 | # X11/wayland/OpenGL libraries dynamically and we need it to find
237 | # the distro libraries. We achieve this with a wrapper that sets
238 | # a custom LD_LIBRARY_PATH that **prefers** Nix libraries, but has
239 | # the ability to fall back to distro lib dirs when needed. This
240 | # combines the best of two worlds: we ship most libraries with
241 | # us and ditch potential ABI issues for those and load distro libs
242 | # for stuff that simply isn't portable (crucially: OpenGL).
243 | appImageLibDirs = [
244 | # Nix system paths
245 | "${pkgs.glibc}/lib"
246 | "${pkgs.stdenv.cc.libc.libgcc.libgcc}/lib"
247 |
248 | # Distro library paths
249 | "/usr/lib/${system}-gnu" # Debian, Ubuntu
250 | "/usr/lib" # Arch, Alpine
251 | "/usr/lib64" # Fedora
252 | ];
253 | appImageDevfiler = pkgs.runCommand "devfiler-stripped"
254 | {
255 | env.unstripped = buildDevfiler { };
256 | nativeBuildInputs = with pkgs; [ binutils patchelf ];
257 | meta.mainProgram = "devfiler";
258 | } ''
259 | cp -R $unstripped $out
260 | chmod -R +w $out
261 | strip $out/bin/devfiler
262 | patchelf --shrink-rpath $out/bin/devfiler
263 | '';
264 | appImageWrapper = pkgs.writeShellScriptBin "devfiler-appimage" ''
265 | export LD_LIBRARY_PATH=${lib.concatStringsSep ":" appImageLibDirs}
266 | ${lib.getExe appImageDevfiler} "$@"
267 | '';
268 |
269 | # Wrapped variant of devfiler that uses the Distro's libgl.
270 | devfilerDistroGL = pkgs.writeShellScriptBin "devfiler-distro-gl" ''
271 | export LD_LIBRARY_PATH=${lib.concatStringsSep ":" appImageLibDirs}
272 | ${lib.getExe (buildDevfiler {})} "$@"
273 | '';
274 |
275 | # Provides a basic development shell with all dependencies.
276 | devShell = pkgs.mkShell {
277 | packages = with pkgs; [ cargo ];
278 | inputsFrom = [ (buildDevfiler { profile = "dev"; }) ];
279 | LIBCLANG_PATH = llvm.libclang.lib + "/lib/";
280 | LD_LIBRARY_PATH = lib.optionalString isLinux linuxDynamicLibs;
281 | };
282 | in
283 | {
284 | formatter = pkgs.nixpkgs-fmt;
285 | devShells.default = devShell;
286 | packages = {
287 | inherit rocksdb;
288 | default = buildDevfiler { };
289 | release = buildDevfiler { };
290 | dev = buildDevfiler { profile = "dev"; };
291 | lto = buildDevfiler { profile = "release-lto"; };
292 | } // lib.optionalAttrs isDarwin {
293 | inherit macAppZip;
294 | } // lib.optionalAttrs isLinux {
295 | inherit appImageWrapper devfilerDistroGL;
296 | };
297 | checks.rustfmt = devfilerCheckRustfmt;
298 | }
299 | );
300 | }
301 |
302 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "local>elastic/renovate-config"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | merge_derives = false
--------------------------------------------------------------------------------
/src/collector/mod.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | //! Collection agent service implementation.
19 |
20 | use std::collections::VecDeque;
21 | use std::net::SocketAddr;
22 | use std::sync::atomic::{AtomicU64, Ordering};
23 | use std::sync::{Arc, RwLock};
24 | use tonic::codec::CompressionEncoding;
25 | use tonic::transport::Server;
26 |
27 | /// Logged request.
28 | #[derive(Debug)]
29 | pub struct LoggedRequest {
30 | /// gRPC meta-data.
31 | pub meta: tonic::metadata::MetadataMap,
32 |
33 | /// Request type.
34 | pub kind: &'static str,
35 |
36 | /// Timestamp when we received the request.
37 | pub timestamp: chrono::DateTime,
38 |
39 | /// Payload after conversion to JSON-like data-structure.
40 | pub payload: serde_json::Value,
41 | }
42 |
43 | /// Collector info and statistics.
44 | #[derive(Debug)]
45 | pub struct Stats {
46 | pub listen_addr: SocketAddr,
47 | pub msgs_processed: AtomicU64,
48 | pub ring: std::sync::RwLock>>,
49 | }
50 |
51 | impl Stats {
52 | /// Log a gRPC message into the ring buffer.
53 | pub fn log_request(&self, req: &tonic::Request) {
54 | self.msgs_processed.fetch_add(1, Ordering::Relaxed);
55 |
56 | let Ok(payload) = serde_json::to_value(req.get_ref()) else {
57 | return;
58 | };
59 |
60 | let logged = Arc::new(LoggedRequest {
61 | payload,
62 | timestamp: chrono::Utc::now(),
63 | kind: std::any::type_name::(),
64 | meta: req.metadata().clone(),
65 | });
66 |
67 | let mut ring = self.ring.write().unwrap();
68 | ring.push_back(logged);
69 | if ring.len() == ring.capacity() {
70 | ring.pop_front();
71 | }
72 | }
73 | }
74 |
75 | /// OTel Profiling collector server.
76 | ///
77 | /// Arc-like behavior: cloned instances refer to the same statistics.
78 | #[derive(Debug, Clone)]
79 | pub struct Collector {
80 | stats: Arc,
81 | }
82 |
83 | impl Collector {
84 | pub fn new(listen_addr: SocketAddr) -> Self {
85 | Self {
86 | stats: Arc::new(Stats {
87 | listen_addr,
88 | msgs_processed: 0.into(),
89 | ring: RwLock::new(VecDeque::with_capacity(100)),
90 | }),
91 | }
92 | }
93 |
94 | pub async fn serve(&self) -> anyhow::Result<()> {
95 | let otlp_server = otlp::ProfilesService::new(self.stats.clone());
96 |
97 | tracing::info!("Collector listening on {}", self.stats.listen_addr);
98 |
99 | let otlp_collector = otlp::ProfilesServiceServer::new(otlp_server)
100 | .accept_compressed(CompressionEncoding::Gzip)
101 | .max_decoding_message_size(16 * 1024 * 1024);
102 |
103 | Server::builder()
104 | .add_service(otlp_collector)
105 | .serve(self.stats.listen_addr)
106 | .await?;
107 |
108 | Ok(())
109 | }
110 |
111 | pub fn stats(&self) -> &Stats {
112 | &*self.stats
113 | }
114 | }
115 |
116 | mod otlp;
117 |
--------------------------------------------------------------------------------
/src/collector/otlp/mod.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | mod pb;
19 | mod service;
20 |
21 | pub use pb::collector::profiles::v1development::profiles_service_server::ProfilesServiceServer;
22 | pub use service::ProfilesService;
23 |
--------------------------------------------------------------------------------
/src/collector/otlp/pb.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | //! Protobuf types for the OTel profiling protocol.
19 |
20 | pub mod common {
21 | pub mod v1 {
22 | tonic::include_proto!("opentelemetry.proto.common.v1");
23 | }
24 | }
25 |
26 | pub mod resource {
27 | pub mod v1 {
28 | tonic::include_proto!("opentelemetry.proto.resource.v1");
29 | }
30 | }
31 |
32 | pub mod collector {
33 | pub mod profiles {
34 | pub mod v1development {
35 | tonic::include_proto!("opentelemetry.proto.collector.profiles.v1development");
36 | }
37 | }
38 | }
39 |
40 | pub mod profiles {
41 | pub mod v1development {
42 | tonic::include_proto!("opentelemetry.proto.profiles.v1development");
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/log.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | use std::{collections::VecDeque, fmt::Debug, sync::Mutex};
19 | use tracing::field::{Field, Visit};
20 | use tracing::level_filters::LevelFilter;
21 | use tracing::{Event, Subscriber};
22 | use tracing_subscriber::fmt::SubscriberBuilder;
23 | use tracing_subscriber::layer::{Context, SubscriberExt as _};
24 | use tracing_subscriber::registry::LookupSpan;
25 | use tracing_subscriber::util::SubscriberInitExt as _;
26 | use tracing_subscriber::{EnvFilter, Layer};
27 |
28 | const LOG_RING_CAP: usize = 16 * 1024;
29 |
30 | lazy_static::lazy_static! {
31 | static ref COLLECTOR: Collector = Collector::default();
32 | }
33 |
34 | pub fn install() {
35 | let filter = EnvFilter::from_env("DEVFILER_LOG")
36 | .add_directive(LevelFilter::WARN.into())
37 | .add_directive("devfiler=info".parse().expect("must parse"));
38 |
39 | SubscriberBuilder::default()
40 | .with_env_filter(filter)
41 | .finish()
42 | .with(&*COLLECTOR)
43 | .init();
44 | }
45 |
46 | pub fn tail(limit: usize) -> Vec {
47 | let ring = COLLECTOR.ring.lock().unwrap();
48 | ring.iter().rev().take(limit).cloned().collect()
49 | }
50 |
51 | #[derive(Debug, Clone)]
52 | pub struct LoggedMessage {
53 | pub time: chrono::DateTime,
54 | pub level: tracing::Level,
55 | pub target: String,
56 | pub message: String,
57 | }
58 |
59 | #[derive(Debug, Default)]
60 | struct Collector {
61 | ring: Mutex>,
62 | }
63 |
64 | impl Layer for &'static Collector
65 | where
66 | S: Subscriber + for<'a> LookupSpan<'a>,
67 | {
68 | fn on_event(&self, event: &Event<'_>, _ctx: Context<'_, S>) {
69 | struct FieldVisitor(Option);
70 |
71 | impl<'a> Visit for FieldVisitor {
72 | fn record_debug(&mut self, field: &Field, value: &dyn Debug) {
73 | if field.name() == "message" {
74 | self.0 = Some(format!("{:?}", value))
75 | }
76 | }
77 | }
78 |
79 | let mut visitor = FieldVisitor(None);
80 |
81 | event.record(&mut visitor);
82 |
83 | let Some(message) = visitor.0 else {
84 | return;
85 | };
86 |
87 | let meta = event.metadata();
88 |
89 | let mut ring = self.ring.lock().unwrap();
90 |
91 | if ring.len() > LOG_RING_CAP {
92 | ring.pop_front();
93 | }
94 |
95 | ring.push_back(LoggedMessage {
96 | time: chrono::Utc::now(),
97 | level: *meta.level(),
98 | target: meta.target().to_owned(),
99 | message,
100 | });
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | use anyhow::Ok;
19 |
20 | mod collector;
21 | mod log;
22 | mod storage;
23 | mod symbolizer;
24 | mod ui;
25 |
26 | #[global_allocator]
27 | static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
28 |
29 | fn main() -> anyhow::Result<()> {
30 | log::install();
31 |
32 | if std::env::args().any(|x| x == "-v" || x == "--version") {
33 | println!("Version: v{}", env!("CARGO_PKG_VERSION"));
34 | return Ok(());
35 | }
36 |
37 | let rt = tokio::runtime::Runtime::new()?;
38 | let _rt_guard = rt.enter(); // make rt avail on main thread
39 |
40 | let collector_addr = "0.0.0.0:11000".parse().unwrap();
41 | let collector = collector::Collector::new(collector_addr);
42 |
43 | if std::env::args().any(|x| x == "--collector-only") {
44 | rt.block_on(collector.serve())?;
45 | } else {
46 | let symb_endpoint = std::env::args()
47 | .collect::>()
48 | .windows(2)
49 | .find(|pair| pair[0] == "--symb-endpoint")
50 | .map(|pair| pair[1].clone())
51 | .unwrap_or_else(|| String::new());
52 |
53 | rt.spawn(symbolizer::monitor_executables(symb_endpoint));
54 | let collector2 = collector.clone();
55 | rt.spawn(async move { collector2.serve().await });
56 | ui::gui_thread(collector).unwrap();
57 | }
58 |
59 | Ok(())
60 | }
61 |
--------------------------------------------------------------------------------
/src/storage/dbtypes.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | //! Types stored in database tables that aren't specific to a particular table.
19 |
20 | use crate::storage::TableKey;
21 |
22 | /// 64-bit UTC unix timestamp.
23 | pub type UtcTimestamp = u64;
24 |
25 | /// Globally unique identifier for an executable.
26 | pub type FileId = symblib::fileid::FileId;
27 |
28 | /// Virtual address in the object file's address space.
29 | pub type VirtAddr = symblib::VirtAddr;
30 |
31 | /// Wrapper type providing rkyv "with" traits.
32 | #[derive(PartialEq, Eq, Default, Hash, Copy, Clone)]
33 | #[repr(transparent)]
34 | pub struct RkyvFileId(u128);
35 |
36 | impl rkyv::with::ArchiveWith for RkyvFileId {
37 | type Archived = rkyv::Archived;
38 | type Resolver = rkyv::Resolver;
39 |
40 | unsafe fn resolve_with(
41 | field: &FileId,
42 | pos: usize,
43 | _resolver: Self::Resolver,
44 | out: *mut Self::Archived,
45 | ) {
46 | use rkyv::Archive as _;
47 | u128::from(*field).resolve(pos, (), out)
48 | }
49 | }
50 |
51 | impl rkyv::with::SerializeWith for RkyvFileId
52 | where
53 | u128: rkyv::Serialize,
54 | {
55 | fn serialize_with(field: &FileId, serializer: &mut S) -> Result {
56 | use rkyv::Serialize as _;
57 | u128::from(*field).serialize(serializer)
58 | }
59 | }
60 |
61 | impl rkyv::with::DeserializeWith, FileId, D>
62 | for RkyvFileId
63 | where
64 | rkyv::Archived: rkyv::Deserialize,
65 | {
66 | fn deserialize_with(
67 | field: &rkyv::Archived,
68 | deserializer: &mut D,
69 | ) -> Result {
70 | use rkyv::Deserialize as _;
71 | Ok(field.deserialize(deserializer)?.into())
72 | }
73 | }
74 |
75 | impl TableKey for FileId {
76 | type B = [u8; 16];
77 |
78 | fn from_raw(data: Self::B) -> Self {
79 | Self::from(u128::from_le_bytes(data))
80 | }
81 |
82 | fn into_raw(self) -> Self::B {
83 | u128::from(self).to_le_bytes()
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/storage/errorspec.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | //! Access to the information from `errors.json`.
19 |
20 | use lazy_static::lazy_static;
21 | use std::collections::HashMap;
22 |
23 | /// Information about an UP error.
24 | #[derive(Debug, serde::Deserialize)]
25 | pub struct ErrorSpec {
26 | pub id: u64,
27 | pub name: &'static str,
28 | #[allow(dead_code)]
29 | pub description: &'static str,
30 | #[serde(default)]
31 | #[allow(dead_code)]
32 | pub obsolete: bool,
33 | }
34 |
35 | /// Get the specification for a given error by its ID.
36 | pub fn error_spec_by_id(id: u64) -> Option<&'static ErrorSpec> {
37 | SPECS.1.get(&id)
38 | }
39 |
40 | /// UP's `errors.json` embedded into this executable.
41 | static ERROR_JSON: &str = include_str!(concat!(
42 | env!("CARGO_MANIFEST_DIR"),
43 | "/opentelemetry-ebpf-profiler/tools/errors-codegen/errors.json"
44 | ));
45 |
46 | fn parse_embedded_spec() -> (bool, HashMap) {
47 | match serde_json::from_str::>(&ERROR_JSON) {
48 | Ok(x) => (true, x.into_iter().map(|x| (x.id, x)).collect()),
49 | Err(e) => {
50 | tracing::error!("Failed to parse embedded `errors.json`: {e:?}");
51 | return (false, HashMap::new());
52 | }
53 | }
54 | }
55 |
56 | lazy_static! {
57 | static ref SPECS: (bool, HashMap) = parse_embedded_spec();
58 | }
59 |
60 | #[cfg(test)]
61 | mod tests {
62 | #[test]
63 | fn parses() {
64 | assert!(super::SPECS.0);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/storage/metricspec.rs:
--------------------------------------------------------------------------------
1 | // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2 | // or more contributor license agreements. See the NOTICE file distributed with
3 | // this work for additional information regarding copyright
4 | // ownership. Elasticsearch B.V. licenses this file to you under
5 | // the Apache License, Version 2.0 (the "License"); you may
6 | // not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing,
12 | // software distributed under the License is distributed on an
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | // KIND, either express or implied. See the License for the
15 | // specific language governing permissions and limitations
16 | // under the License.
17 |
18 | //! Access to the information from `metrics.json`.
19 |
20 | use lazy_static::lazy_static;
21 | use serde::Deserialize;
22 | use std::collections::HashMap;
23 |
24 | /// Determines whether the metric is a counter or a gauge.
25 | #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Deserialize)]
26 | #[serde(rename_all = "lowercase")]
27 | pub enum MetricKind {
28 | Counter,
29 | Gauge,
30 | }
31 |
32 | /// Information about a metric.
33 | #[derive(Debug, Deserialize)]
34 | pub struct MetricSpec {
35 | pub id: u32,
36 | #[allow(dead_code)]
37 | pub unit: Option<&'static str>,
38 | #[allow(dead_code)]
39 | pub name: &'static str,
40 | pub field: Option<&'static str>,
41 | #[serde(rename = "type")]
42 | pub kind: MetricKind,
43 | }
44 |
45 | /// Get the specification for a given metric by its ID.
46 | pub fn metric_spec_by_id(id: u32) -> Option<&'static MetricSpec> {
47 | SPECS.1.get(id as usize).map(Option::as_ref).flatten()
48 | }
49 |
50 | /// UP's `metrics.json` embedded into this executable.
51 | static METRICS_JSON: &str = include_str!(concat!(
52 | env!("CARGO_MANIFEST_DIR"),
53 | "/opentelemetry-ebpf-profiler/metrics/metrics.json"
54 | ));
55 |
56 | fn parse_embedded_spec() -> (bool, Vec