blob: 7053ff3a575738e26d9b4e35b59d21e6045ac2d7 [file]
// Copyright 2024 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.
#ifndef SRC_UI_BIN_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
#define SRC_UI_BIN_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
#include <fidl/fuchsia.diagnostics/cpp/fidl.h>
#include <lib/component/incoming/cpp/protocol.h>
#include "src/ui/bin/system_monitor/system_monitor_renderer.h"
namespace system_monitor {
// This class uses archiveAccessor and batchIterator to get diagnostic
// information like platform metrics which include CPU usage.
class SystemMonitor {
public:
// Class constructor initializes the parameters of INSPECT data
SystemMonitor();
// These functions uses the iterator to access inspect diagnostic and turn
// all the json format content into std::string and
// returns a vector of strings.
void ConnectToArchiveAccessor();
void InitializeRenderer();
void UpdateRecentDiagnostic();
void PrintRecentDiagnostic();
std::vector<std::string> ParseBatch(
const std::vector<fuchsia_diagnostics::FormattedContent>& batch);
std::string GetTargetFromDiagnostics(std::vector<std::string> recent_diagnostics);
std::string GetCPUData();
private:
// The most recent batch of inspect data, fetched by the UpdateRecentDiagnostic() function.
std::vector<fuchsia_diagnostics::FormattedContent> batch_;
// a batchIterator client initialized in the UpdateRecentDiagnostic() function.
fidl::SyncClient<fuchsia_diagnostics::BatchIterator> iterator_;
// archiveAccessor client initialized in the ConnectToArchiveAccessor() function to get a new
// batch of inspect data.
fidl::SyncClient<fuchsia_diagnostics::ArchiveAccessor> accessor_;
// streamParameters initialized in the class constructor.
fuchsia_diagnostics::StreamParameters params_;
SystemMonitorRenderer renderer_;
};
} // namespace system_monitor
#endif // SRC_UI_BIN_SYSTEM_MONITOR_SYSTEM_MONITOR_H_