mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Refactor the memory profiler code to return the struct. (#37155)
Refactor the memory profiler code to return the struct and handle the serializing in servointernal page. This allows other users of the memory profiler to see the whole report without parsing json. Testing: I do not know if the memory page is covered by tests. --------- Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
ac06b1cfcf
commit
2d3a7c87c2
3 changed files with 21 additions and 18 deletions
|
@ -12,9 +12,9 @@ use ipc_channel::ipc::{self, IpcReceiver};
|
|||
use ipc_channel::router::ROUTER;
|
||||
use log::debug;
|
||||
use profile_traits::mem::{
|
||||
MemoryReportResult, ProfilerChan, ProfilerMsg, Report, Reporter, ReporterRequest, ReportsChan,
|
||||
MemoryReport, MemoryReportResult, ProfilerChan, ProfilerMsg, Report, Reporter, ReporterRequest,
|
||||
ReportsChan,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::system_reporter;
|
||||
|
||||
|
@ -100,28 +100,18 @@ impl Profiler {
|
|||
ProfilerMsg::Report(sender) => {
|
||||
let main_pid = std::process::id();
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct JsonReport {
|
||||
pid: u32,
|
||||
#[serde(rename = "isMainProcess")]
|
||||
is_main_process: bool,
|
||||
reports: Vec<Report>,
|
||||
}
|
||||
|
||||
let reports = self.collect_reports();
|
||||
// Turn the pid -> reports map into a vector and add the
|
||||
// hint to find the main process.
|
||||
let json_reports: Vec<JsonReport> = reports
|
||||
let results: Vec<MemoryReport> = reports
|
||||
.into_iter()
|
||||
.map(|(pid, reports)| JsonReport {
|
||||
.map(|(pid, reports)| MemoryReport {
|
||||
pid,
|
||||
reports,
|
||||
is_main_process: pid == main_pid,
|
||||
})
|
||||
.collect();
|
||||
let content = serde_json::to_string(&json_reports)
|
||||
.unwrap_or_else(|_| "{ error: \"failed to create memory report\"}".to_owned());
|
||||
let _ = sender.send(MemoryReportResult { content });
|
||||
let _ = sender.send(MemoryReportResult { results });
|
||||
true
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue