Skip to content

Commit

Permalink
Add user-event-format-string-channels config
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Jul 14, 2024
1 parent 34945a2 commit 8af433b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "modality-trace-recorder-plugin"
version = "0.27.2"
version = "0.28.0"
edition = "2021"
authors = ["Jon Lamb <[email protected]>"]
description = "A Modality reflector plugin suite and ingest adapter library for Percepio's TraceRecorder data"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ These sections are the same for each of the plugins.
- `ignored-object-classes` — Array of object classes to ignore processing during ingest (e.g. `[queue, semaphore]`)
- `user-event-channel` — Instead of `USER_EVENT @ <task-name>`, use the user event channel as the event name (`<channel> @ <task-name>`).
- `user-event-format-string` — Instead of `USER_EVENT @ <task-name>`, use the user event format string as the event name (`<format-string> @ <task-name>`).
- `user-event-format-string-channels` — Same as `user-event-format-string` but for a specific set of channels.
- `[[user-event-channel-name]]` — Use a custom event name whenever a user event with a matching channel is processed.
* `channel`— The input channel name to match on.
* `event-name`— The Modality event name to use.
Expand Down Expand Up @@ -301,7 +302,7 @@ reflector configuration file, e.g. `[plugins.ingest.collectors.trace-recorder-tc
- `disable-control-plane` — Disable sending control plane commands to the target. By default, `CMD_SET_ACTIVE` is sent on startup and shutdown to start and stop tracing on the target.
- `restart` — Send a stop command before a start command to reset tracing on the target.
- `connect-timeout` — Specify a connection timeout. Accepts durations like "10ms" or "1minute 2seconds 22ms".
- `remote` — The remote address and port to connect to. The default is `127.0.0.1:8888`.
- `remote` — The remote TCP server URL or `address:port` to connect to. The default is `127.0.0.1:8888`.

### ITM Collector Section

Expand Down
26 changes: 26 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use auxon_sdk::{
};
use derive_more::{Deref, From, Into};
use serde::Deserialize;
use std::collections::HashSet;
use std::env;
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -46,6 +47,7 @@ pub struct PluginConfig {
pub ignored_object_classes: IgnoredObjectClasses,
pub user_event_channel: bool,
pub user_event_format_string: bool,
pub user_event_format_string_channels: HashSet<String>,
pub user_event_channel_rename_map: RenameMap,
pub user_event_formatted_string_rename_map: RenameMap,
pub user_event_fmt_arg_attr_keys: FormatArgAttributeKeysSet,
Expand Down Expand Up @@ -291,6 +293,17 @@ impl TraceRecorderConfig {
} else {
cfg_plugin.user_event_channel
},
user_event_format_string_channels: if !tr_opts
.user_event_format_string_channel
.is_empty()
{
tr_opts
.user_event_format_string_channel
.into_iter()
.collect()
} else {
cfg_plugin.user_event_format_string_channels
},
user_event_format_string: if tr_opts.user_event_format_string {
true
} else {
Expand Down Expand Up @@ -385,6 +398,7 @@ mod internal {
pub ignored_object_classes: IgnoredObjectClasses,
pub user_event_channel: bool,
pub user_event_format_string: bool,
pub user_event_format_string_channels: Vec<String>,
#[serde(rename = "user-event-channel-name")]
pub user_event_channel_rename_map: RenameMap,
#[serde(rename = "user-event-formatted-string-name")]
Expand All @@ -409,6 +423,10 @@ mod internal {
ignored_object_classes: c.ignored_object_classes,
user_event_channel: c.user_event_channel,
user_event_format_string: c.user_event_format_string,
user_event_format_string_channels: c
.user_event_format_string_channels
.into_iter()
.collect(),
user_event_channel_rename_map: c.user_event_channel_rename_map,
user_event_formatted_string_rename_map: c.user_event_formatted_string_rename_map,
user_event_fmt_arg_attr_keys: c.user_event_fmt_arg_attr_keys,
Expand Down Expand Up @@ -560,6 +578,7 @@ run-id = 'a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d1'
time-domain = 'a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d1'
startup-task-name = 'm3'
user-event-channel = true
user-event-format-string-channels = ['info', 'err']
user-event-format-string = true
interaction-mode = "ipc"
single-task-timeline = true
Expand Down Expand Up @@ -798,6 +817,10 @@ breakpoint = "main"
ignored_object_classes: Default::default(),
user_event_channel: true,
user_event_format_string: true,
user_event_format_string_channels: ["info", "err"]
.into_iter()
.map(|s| s.to_string())
.collect(),
user_event_channel_rename_map: vec![RenameMapItem {
input: "act-cmd".to_owned(),
event_name: "MY_EVENT".to_owned()
Expand Down Expand Up @@ -894,6 +917,7 @@ breakpoint = "main"
ignored_object_classes: Default::default(),
user_event_channel: true,
user_event_format_string: true,
user_event_format_string_channels: Default::default(),
user_event_channel_rename_map: vec![RenameMapItem {
input: "act-cmd".to_owned(),
event_name: "MY_EVENT".to_owned()
Expand Down Expand Up @@ -992,6 +1016,7 @@ breakpoint = "main"
.collect(),
user_event_channel: true,
user_event_format_string: true,
user_event_format_string_channels: Default::default(),
user_event_channel_rename_map: vec![RenameMapItem {
input: "act-cmd".to_owned(),
event_name: "MY_EVENT".to_owned()
Expand Down Expand Up @@ -1101,6 +1126,7 @@ breakpoint = "main"
.collect(),
user_event_channel: true,
user_event_format_string: true,
user_event_format_string_channels: Default::default(),
user_event_channel_rename_map: vec![RenameMapItem {
input: "act-cmd".to_owned(),
event_name: "MY_EVENT".to_owned()
Expand Down
11 changes: 11 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ pub struct TraceRecorderOpts {
)]
pub user_event_format_string: bool,

/// Instead of `USER_EVENT @ <task-name>`, use the user event format string
/// as the event name (`<format-string> @ <task-name>`) for the given channel.
/// Can be supplied multiple times.
#[clap(
long,
name = "user-event-format-string-channel",
conflicts_with = "user-event-format-string",
help_heading = "TRACE RECORDER CONFIGURATION"
)]
pub user_event_format_string_channel: Vec<String>,

/// Use a custom event name whenever a user event with a matching
/// channel is processed.
/// Can be supplied multiple times.
Expand Down
8 changes: 7 additions & 1 deletion src/recorder_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,13 @@ impl RecorderDataExt for RecorderData {
}

Event::User(ev) => {
if cfg.user_event_channel {
if cfg
.user_event_format_string_channels
.contains(ev.channel.as_str())
{
// Use the formatted string as the event name
attrs.insert(EventAttrKey::Name, ev.formatted_string.to_string().into());
} else if cfg.user_event_channel {
// Use the channel as the event name
attrs.insert(EventAttrKey::Name, ev.channel.to_string().into());
} else if cfg.user_event_format_string {
Expand Down

0 comments on commit 8af433b

Please sign in to comment.