blob: 6acf4ce5f7c156201e406e36f9f93f6cfa3cf86a [file] [log] [blame]
// 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 crate::logs::stored_message::StoredMessage;
use diagnostics_data::Severity;
use fuchsia_inspect::{IntProperty, Node, NumericProperty, Property, UintProperty};
use fuchsia_inspect_derive::Inspect;
#[derive(Debug, Default, Inspect)]
pub struct LogStreamStats {
sockets_opened: UintProperty,
sockets_closed: UintProperty,
last_timestamp: IntProperty,
total: LogCounter,
rolled_out: LogCounter,
fatal: LogCounter,
error: LogCounter,
warn: LogCounter,
info: LogCounter,
debug: LogCounter,
trace: LogCounter,
inspect_node: Node,
impl LogStreamStats {
pub fn open_socket(&self) {
pub fn close_socket(&self) {
pub fn increment_rolled_out(&self, msg: &StoredMessage) {
pub fn ingest_message(&self, msg: &StoredMessage) {
match msg.severity() {
Severity::Trace => self.trace.count(msg),
Severity::Debug => self.debug.count(msg),
Severity::Info =>,
Severity::Warn => self.warn.count(msg),
Severity::Error => self.error.count(msg),
Severity::Fatal => self.fatal.count(msg),
#[derive(Debug, Default, Inspect)]
struct LogCounter {
number: UintProperty,
bytes: UintProperty,
inspect_node: Node,
impl LogCounter {
fn count(&self, msg: &StoredMessage) {
self.bytes.add(msg.size() as u64);