sl4f_lib/tracing/
types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use serde::{Deserialize, Serialize};

/// Enum for supported Tracing commands.
pub enum TracingMethod {
    Initialize,
    Start,
    Stop,
    Terminate,
}

#[derive(Deserialize)]
pub struct InitializeRequest {
    /// Categories to trace.
    ///
    /// Possible values:
    /// * Omitted (None) for default categories
    /// * Explicit empty list for all categories
    /// * Explicit list of categories to trace
    pub categories: Option<Vec<String>>,
    /// Buffer size to use in MB
    ///
    /// Note: This size is only a suggestion to trace_manager. In particular, very large values
    /// will likely not be respected.
    pub buffer_size: Option<u32>,
}

/// What to do with trace data
#[derive(Deserialize)]
pub enum ResultsDestination {
    /// Completely ignore trace data. Generally used to clean up a trace session left behind by
    /// another trace controller.
    Ignore,
    /// Have trace manager write out the trace data, have the facade read it and return it in the
    /// response to the terminate request.
    WriteAndReturn,
}

impl Default for ResultsDestination {
    fn default() -> Self {
        ResultsDestination::WriteAndReturn
    }
}

#[derive(Deserialize)]
pub struct TerminateRequest {
    /// Whether to download results from the trace. Defaults to ResultsDestination::WriteAndReturn
    ///
    /// Currently, the main use for ResultsDestination::Ignore to clean up a trace session left
    /// behind by another trace controller.
    #[serde(default)]
    pub results_destination: ResultsDestination,
}

#[derive(Serialize)]
pub struct TerminateResponse {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
}

impl std::str::FromStr for TracingMethod {
    type Err = anyhow::Error;

    fn from_str(method: &str) -> Result<Self, Self::Err> {
        match method {
            "Initialize" => Ok(TracingMethod::Initialize),
            "Start" => Ok(TracingMethod::Start),
            "Stop" => Ok(TracingMethod::Stop),
            "Terminate" => Ok(TracingMethod::Terminate),
            _ => return Err(format_err!("invalid Traceutil Facade method: {}", method)),
        }
    }
}