Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions benches/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

#[cfg(feature = "test_utilities")]
use criterion::{criterion_group, criterion_main, Criterion};

#[cfg(feature = "test_utilities")]
use event_manager::utilities::subscribers::{
CounterInnerMutSubscriber, CounterSubscriber, CounterSubscriberWithData,
};
#[cfg(feature = "test_utilities")]
use event_manager::{EventManager, EventSubscriber, MutEventSubscriber, SubscriberOps};
#[cfg(feature = "test_utilities")]
use std::sync::{Arc, Mutex};

// Test the performance of event manager when it manages a single subscriber type.
// The performance is assessed under stress, all added subscribers have active events.
#[cfg(feature = "test_utilities")]
fn run_basic_subscriber(c: &mut Criterion) {
let no_of_subscribers = 200;

Expand All @@ -31,6 +36,7 @@ fn run_basic_subscriber(c: &mut Criterion) {

// Test the performance of event manager when the subscribers are wrapped in an Arc<Mutex>.
// The performance is assessed under stress, all added subscribers have active events.
#[cfg(feature = "test_utilities")]
fn run_arc_mutex_subscriber(c: &mut Criterion) {
let no_of_subscribers = 200;

Expand All @@ -52,6 +58,7 @@ fn run_arc_mutex_subscriber(c: &mut Criterion) {
// Test the performance of event manager when the subscribers are wrapped in an Arc, and they
// leverage inner mutability to update their internal state.
// The performance is assessed under stress, all added subscribers have active events.
#[cfg(feature = "test_utilities")]
fn run_subscriber_with_inner_mut(c: &mut Criterion) {
let no_of_subscribers = 200;

Expand All @@ -75,6 +82,7 @@ fn run_subscriber_with_inner_mut(c: &mut Criterion) {
// (using CounterSubscriberWithData).
// The performance is assessed under stress, all added subscribers have active events, and the
// CounterSubscriberWithData subscribers have multiple active events.
#[cfg(feature = "test_utilities")]
fn run_multiple_subscriber_types(c: &mut Criterion) {
let no_of_subscribers = 100;

Expand Down Expand Up @@ -102,6 +110,7 @@ fn run_multiple_subscriber_types(c: &mut Criterion) {

// Test the performance of event manager when it manages a single subscriber type.
// Just a few of the events are active in this test scenario.
#[cfg(feature = "test_utilities")]
fn run_with_few_active_events(c: &mut Criterion) {
let no_of_subscribers = 200;

Expand All @@ -124,6 +133,7 @@ fn run_with_few_active_events(c: &mut Criterion) {
});
}

#[cfg(feature = "test_utilities")]
criterion_group! {
name = benches;
config = Criterion::default()
Expand All @@ -133,6 +143,10 @@ criterion_group! {
run_multiple_subscriber_types, run_with_few_active_events
}

#[cfg(feature = "test_utilities")]
criterion_main! {
benches
}

#[cfg(not(feature = "test_utilities"))]
fn main() {}
2 changes: 1 addition & 1 deletion rust-vmm-ci
2 changes: 1 addition & 1 deletion src/utilities/subscribers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// 3. CounterInnerMutSubscriber:
/// - a dummy subscriber that increments a counter on events
/// - the subscriber makes use of inner mutability; multi-threaded applications might want to
/// use inner mutability instead of having something heavy weight (i.e. Arc<Mutex>).
/// use inner mutability instead of having something heavy weight (i.e. `Arc<Mutex>`).
/// - this subscriber implement `EventSubscriber`.
use std::fmt::{Display, Formatter, Result};
use std::os::unix::io::AsRawFd;
Expand Down
2 changes: 2 additions & 0 deletions tests/basic_event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// The application has an `EventManager` and can register multiple subscribers
// of type `CounterSubscriber`.

#![cfg(feature = "test_utilities")]

use std::ops::Drop;

use event_manager::utilities::subscribers::CounterSubscriber;
Expand Down
1 change: 1 addition & 0 deletions tests/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

#![cfg(feature = "remote_endpoint")]
#![cfg(feature = "test_utilities")]

use std::any::Any;
use std::result;
Expand Down
2 changes: 2 additions & 0 deletions tests/multi_threaded.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

#![cfg(feature = "test_utilities")]

use std::sync::{Arc, Mutex};
use std::thread;

Expand Down
2 changes: 2 additions & 0 deletions tests/regressions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (C) 2020 Alibaba Cloud. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

#![cfg(feature = "test_utilities")]

use event_manager::utilities::subscribers::CounterSubscriberWithData;
use event_manager::{EventManager, SubscriberOps};

Expand Down