blob: c9ee93672ad05ccc2db8f9a747a31c757438de8f [file] [log] [blame]
// Copyright 2019 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 GARNET_BIN_SYSTEM_MONITOR_HARVESTER_GATHER_THREADS_AND_CPU_H_
#define GARNET_BIN_SYSTEM_MONITOR_HARVESTER_GATHER_THREADS_AND_CPU_H_
#include "gather_category.h"
namespace harvester {
class TaskTree;
// Determine which actions to take at each interval.
class TaskActions {
public:
TaskActions() = default;
// Asking which actions to take.
bool WantRefresh() { return !(counter_ % REFRESH_INTERVAL); }
// Call this at the end of each interval.
void NextInterval() { ++counter_; }
private:
// Only gather and upload this data every Nth time this is called. Reuse the
// same task info for the other (N - 1) times. This is an optimization. If
// the overhead/time to gather this information is reduced then this
// optimization may be removed.
static const int REFRESH_INTERVAL = {20};
int counter_ = 0;
};
// Gather samples for threads and global CPU stats.
class GatherThreadsAndCpu : public GatherCategory {
public:
GatherThreadsAndCpu(zx_handle_t root_resource,
harvester::DockyardProxy* dockyard_proxy);
~GatherThreadsAndCpu() override;
// GatherCategory.
void Gather() override;
private:
TaskActions actions_;
TaskTree* task_tree_;
GatherThreadsAndCpu() = delete;
};
} // namespace harvester
#endif // GARNET_BIN_SYSTEM_MONITOR_HARVESTER_GATHER_THREADS_AND_CPU_H_