Skip to content

Commit 3bb7c5f

Browse files
authored
profile: Implement MallocSizeOf for GenericCallback (servo#42152)
Implement MallocSizeOf for profile::GenericCallback. Additionally, we implement a more acurate version of MallocSizeOf for GenericSender. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com> Testing: Implementing traits do not need tests. Fixes: servo#42110 Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
1 parent cc56218 commit 3bb7c5f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

components/shared/base/generic_channel.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@ impl<T: Serialize> GenericSender<T> {
196196
}
197197

198198
impl<T: Serialize> MallocSizeOf for GenericSender<T> {
199-
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
200-
0
199+
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
200+
match &self.0 {
201+
GenericSenderVariants::Ipc(ipc_sender) => ipc_sender.size_of(ops),
202+
GenericSenderVariants::Crossbeam(sender) => sender.size_of(ops),
203+
}
201204
}
202205
}
203206

components/shared/profile/generic_callback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

55
use base::generic_channel::SendResult;
6+
use malloc_size_of_derive::MallocSizeOf;
67
use serde::{Deserialize, Serialize};
78

89
use crate::time::{ProfilerCategory, ProfilerChan};
910
use crate::time_profile;
1011

11-
#[derive(Clone, Debug, Serialize, Deserialize)]
12+
#[derive(Clone, Debug, Serialize, Deserialize, MallocSizeOf)]
1213
pub struct GenericCallback<T>
1314
where
1415
T: Serialize + Send + 'static,

components/shared/profile/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct TimerMetadata {
1717
pub incremental: TimerMetadataReflowType,
1818
}
1919

20-
#[derive(Clone, Debug, Deserialize, Serialize)]
20+
#[derive(Clone, Debug, Deserialize, Serialize, MallocSizeOf)]
2121
pub struct ProfilerChan(pub Option<GenericSender<ProfilerMsg>>);
2222

2323
impl ProfilerChan {

0 commit comments

Comments
 (0)