aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/cpu_manager.h
blob: 26ba97aa398e5eed588e31470c28752ffa136319 (plain) (blame)
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
#pragma once

#include "harmonizer.h"
#include "executor_pool.h"
#include "executor_pool_united_workers.h"
#include "balancer.h"

namespace NActors {
    struct TActorSystemSetup;

    class TCpuManager : public TNonCopyable {
        const ui32 ExecutorPoolCount;
        TArrayHolder<TAutoPtr<IExecutorPool>> Executors;
        THolder<TUnitedWorkers> UnitedWorkers;
        THolder<IBalancer> Balancer;
        THolder<IHarmonizer> Harmonizer;
        TCpuManagerConfig Config;

    public:
        explicit TCpuManager(THolder<TActorSystemSetup>& setup);

        void Setup();
        void PrepareStart(TVector<NSchedulerQueue::TReader*>& scheduleReaders, TActorSystem* actorSystem);
        void Start();
        void PrepareStop();
        void Shutdown();
        void Cleanup();

        TVector<IExecutorPool*> GetBasicExecutorPools() const;

        ui32 GetExecutorsCount() const {
            return ExecutorPoolCount;
        }

        IExecutorPool* GetExecutorPool(ui32 poolId) {
            return Executors[poolId].Get();
        }

        void GetPoolStats(ui32 poolId, TExecutorPoolStats& poolStats, TVector<TExecutorThreadStats>& statsCopy) const {
            if (poolId < ExecutorPoolCount) {
                Executors[poolId]->GetCurrentStats(poolStats, statsCopy);
            }
        }

        THarmonizerStats GetHarmonizerStats() const {
            if (Harmonizer) {
                return Harmonizer->GetStats();
            }
            return {};
        }

    private:
        IExecutorPool* CreateExecutorPool(ui32 poolId);
    };
}