Skip to content

Commit 69994af

Browse files
Add builder convenience method to Group (#44)
* Add builder convenience method to Group * Add more detailed documentation on `Group::builder` * Use `Group::builder` within `Group::new` --------- Co-authored-by: Phantomical <phantom@lynches.ca>
1 parent 6c89790 commit 69994af

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

perf-event/src/group.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,36 @@ impl Group {
9999
/// on any CPU. If you need to build a `Group` with different settings you
100100
/// will need to use [`Builder::build_group`].
101101
pub fn new() -> io::Result<Group> {
102-
Builder::new(Software::DUMMY)
103-
.read_format(
104-
ReadFormat::GROUP
105-
| ReadFormat::TOTAL_TIME_ENABLED
106-
| ReadFormat::TOTAL_TIME_RUNNING
107-
| ReadFormat::ID,
108-
)
109-
.build_group()
102+
Self::builder().build_group()
103+
}
104+
105+
/// Construct a [Builder] preconfigured for creating a `Group`.
106+
///
107+
/// Specifically, this creates a builder with the [`Software::DUMMY`] event
108+
/// and with [`read_format`] set to `GROUP | ID | TOTAL_TIME_ENABLED |
109+
/// TOTAL_TIME_RUNNING`. If you override [`read_format`] you will need to
110+
/// ensure that [`ReadFormat::GROUP`] is set, otherwise [`build_group`] will
111+
/// return an error.
112+
///
113+
/// Note that any counter added to this group must observe the same set of
114+
/// CPUs and processes as the group itself. That means if you configure the
115+
/// group to observe a single CPU then the members of the group must also be
116+
/// configured to only observe a single CPU, the same applies when choosing
117+
/// target processes. Failing to follow this will result in an error when
118+
/// adding the counter to the group.
119+
///
120+
/// [`read_format`]: Builder::read_format
121+
/// [`build_group`]: Builder::build_group
122+
pub fn builder() -> Builder<'static> {
123+
let mut builder = Builder::new(Software::DUMMY);
124+
builder.read_format(
125+
ReadFormat::GROUP
126+
| ReadFormat::TOTAL_TIME_ENABLED
127+
| ReadFormat::TOTAL_TIME_RUNNING
128+
| ReadFormat::ID,
129+
);
130+
131+
builder
110132
}
111133

112134
/// Access the internal counter for this group.

0 commit comments

Comments
 (0)