Skip to content

Commit 8c81e6f

Browse files
committed
traced_probes: Add linux.journald data source
Add a new `linux.journald` data source to `traced_probes` that reads log entries from the systemd journal via `libsystemd`. The library is loaded at runtime via dlopen("libsystemd.so.0") so there is no compile-time dependency on libsystemd. New protos: - `JournaldConfig` in `protos/perfetto/config/linux/journald_config.proto` - `JournaldEventPacket` in `protos/perfetto/trace/linux/journald_event.proto` The data source opens the journal with sd_journal_open(), and emits one JournaldEventPacket per entry containing: timestamp, pid, priority, tag, message, uid, comm, systemd_unit, hostname and transport.
1 parent 69f69cf commit 8c81e6f

16 files changed

Lines changed: 1350 additions & 1 deletion

Android.bp

Lines changed: 463 additions & 0 deletions
Large diffs are not rendered by default.

BUILD

Lines changed: 107 additions & 0 deletions
Large diffs are not rendered by default.

protos/perfetto/config/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ perfetto_proto_library("@TYPE@") {
2727
"gpu:@TYPE@",
2828
"inode_file:@TYPE@",
2929
"interceptors:@TYPE@",
30+
"linux:@TYPE@",
3031
"power:@TYPE@",
3132
"priority_boost:@TYPE@",
3233
"process_stats:@TYPE@",

protos/perfetto/config/data_source_config.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import "protos/perfetto/config/test_config.proto";
6161
import "protos/perfetto/config/track_event/track_event_config.proto";
6262
import "protos/perfetto/config/system_info/system_info_config.proto";
6363
import "protos/perfetto/config/chrome/histogram_samples.proto";
64+
import "protos/perfetto/config/linux/journald_config.proto";
6465
import "protos/perfetto/config/qnx/qnx_config.proto";
6566

6667
// The configuration that is passed to each data source when starting tracing.
@@ -305,6 +306,9 @@ message DataSourceConfig {
305306
// Data source name: android.aflags
306307
optional AndroidAflagsConfig android_aflags_config = 140 [lazy = true];
307308

309+
// Data source name: linux.journald
310+
optional JournaldConfig journald_config = 141 [lazy = true];
311+
308312
// Data source name: qnx.kernel
309313
optional QnxConfig qnx_config = 150 [lazy = true];
310314

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2025 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("../../../../gn/proto_library.gni")
16+
17+
perfetto_proto_library("@TYPE@") {
18+
sources = [ "journald_config.proto" ]
19+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2025 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto2";
16+
17+
package perfetto.protos;
18+
19+
// Configuration for the "linux.journald" data source.
20+
// Next field id: 4
21+
message JournaldConfig {
22+
// Minimum syslog priority level to capture (inclusive).
23+
// 0=EMERG, 1=ALERT, 2=CRIT, 3=ERR, 4=WARNING, 5=NOTICE, 6=INFO, 7=DEBUG.
24+
// Default (0 / unset): capture all priorities (equivalent to 7).
25+
optional uint32 min_prio = 1;
26+
27+
// If non-empty, only capture journal entries whose SYSLOG_IDENTIFIER
28+
// matches one of these strings.
29+
repeated string filter_identifiers = 2;
30+
31+
// If non-empty, only capture journal entries from these systemd unit names.
32+
repeated string filter_units = 3;
33+
}

protos/perfetto/trace/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ perfetto_proto_library("non_minimal_@TYPE@") {
9191
"generic_kernel:@TYPE@",
9292
"gpu:@TYPE@",
9393
"interned_data:@TYPE@",
94+
"linux:@TYPE@",
9495
"perfetto:@TYPE@",
9596
"power:@TYPE@",
9697
"profiling:@TYPE@",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2025 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("../../../../gn/proto_library.gni")
16+
17+
perfetto_proto_library("@TYPE@") {
18+
sources = [ "journald_event.proto" ]
19+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (C) 2025 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto2";
16+
17+
package perfetto.protos;
18+
19+
// A journald log event packet, collected from the Linux systemd journal.
20+
// Emitted by the "linux.journald" data source in traced_probes.
21+
// Next field id: 13, statistics starting at 20
22+
message JournaldEventPacket {
23+
// _PID: PID of the process that wrote the log entry (trusted).
24+
optional uint32 pid = 1;
25+
26+
// _TID: thread ID of the logging thread (trusted, set by journald for
27+
// native journal protocol entries). Absent for syslog, stdout-piped, and
28+
// kernel entries.
29+
optional uint32 tid = 2;
30+
31+
// _UID: user ID of the process (trusted).
32+
optional uint32 uid = 3;
33+
34+
// _GID: group ID of the process (trusted).
35+
optional uint32 gid = 4;
36+
37+
// PRIORITY: syslog priority level 0 (EMERG) .. 7 (DEBUG).
38+
optional uint32 prio = 5;
39+
40+
// SYSLOG_IDENTIFIER: program name / tag, set by the logging application.
41+
optional string tag = 6;
42+
43+
// MESSAGE: the human-readable log message text.
44+
optional string message = 7;
45+
46+
// _COMM: short process name as known to the kernel (trusted).
47+
optional string comm = 8;
48+
49+
// _EXE: full executable path (trusted).
50+
optional string exe = 9;
51+
52+
// _SYSTEMD_UNIT: the systemd unit that owns this process (trusted).
53+
optional string systemd_unit = 10;
54+
55+
// _HOSTNAME: hostname of the machine (trusted).
56+
optional string hostname = 11;
57+
58+
// _TRANSPORT: how the entry was received by journald (trusted).
59+
// Values: "audit", "driver", "syslog", "journal", "stdout", "kernel".
60+
optional string transport = 12;
61+
62+
// These statistics emitted once on Flush()
63+
optional uint64 num_total = 20;
64+
optional uint64 num_failed = 21;
65+
optional uint64 num_skipped = 22;
66+
}

protos/perfetto/trace/trace_packet.proto

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import "protos/perfetto/trace/chrome/chrome_trace_event.proto";
5050
import "protos/perfetto/trace/chrome/chrome_trigger.proto";
5151
import "protos/perfetto/trace/chrome/v8.proto";
5252
import "protos/perfetto/trace/clock_snapshot.proto";
53+
import "protos/perfetto/trace/linux/journald_event.proto";
5354
import "protos/perfetto/trace/etw/etw_event_bundle.proto";
5455
import "protos/perfetto/trace/evdev.proto";
5556
import "protos/perfetto/trace/filesystem/inode_file_map.proto";
@@ -119,7 +120,7 @@ package perfetto.protos;
119120
// See the [Buffers and Dataflow](/docs/concepts/buffers.md) doc for details.
120121
//
121122
// Next reserved id: 14 (up to 15).
122-
// Next id: 131.
123+
// Next id: 132.
123124
message TracePacket {
124125
// Encapsulates the state and configuration of the ProtoVM instances running
125126
// when the trace was snapshotted. This allows TP to re-instantiate the VMs
@@ -311,6 +312,8 @@ message TracePacket {
311312

312313
AndroidUserList user_list = 123;
313314

315+
JournaldEventPacket journald_event = 131;
316+
314317
// This field is only used for testing.
315318
// In previous versions of this proto this field had the id 268435455
316319
// This caused many problems:

0 commit comments

Comments
 (0)