SystemInfo.h 2.4 KB
Newer Older
Y
yu yunfeng 已提交
1 2 3 4 5 6 7 8 9 10
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/

#pragma once

#include "sys/types.h"
#include "sys/sysinfo.h"
Y
yu yunfeng 已提交
11 12 13 14 15
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "sys/times.h"
#include "sys/vtimes.h"
Y
yu yunfeng 已提交
16
#include <chrono>
Y
yu yunfeng 已提交
17 18 19 20

#include <unordered_map>
#include <vector>

Y
yu yunfeng 已提交
21 22 23


namespace zilliz {
J
jinhai 已提交
24
namespace milvus {
Y
yu yunfeng 已提交
25 26 27 28
namespace server {

class SystemInfo {
 private:
Y
yu yunfeng 已提交
29 30 31 32
    unsigned long total_ram_ = 0;
    clock_t last_cpu_ = clock_t();
    clock_t last_sys_cpu_ = clock_t();
    clock_t last_user_cpu_ = clock_t();
Y
yu yunfeng 已提交
33
    std::chrono::system_clock::time_point net_time_ = std::chrono::system_clock::now();
Y
yu yunfeng 已提交
34
    int num_processors_ = 0;
K
kun yu 已提交
35
    int num_physical_processors_ = 0;
Y
yu yunfeng 已提交
36
    //number of GPU
Y
yu yunfeng 已提交
37
    unsigned int num_device_ = 0;
Y
yu yunfeng 已提交
38 39
    unsigned long long in_octets_ = 0;
    unsigned long long out_octets_ = 0;
Y
yu yunfeng 已提交
40
    bool initialized_ = false;
Y
yu yunfeng 已提交
41 42 43 44 45 46 47 48

 public:
    static SystemInfo &
    GetInstance(){
        static SystemInfo instance;
        return instance;
    }

Y
yu yunfeng 已提交
49
    void Init();
K
kun yu 已提交
50
    int num_processor() const { return num_processors_;};
K
kun yu 已提交
51
    int num_physical_processors() const { return num_physical_processors_; };
Y
fix  
yu yunfeng 已提交
52
    int num_device() const {return num_device_;};
Y
yu yunfeng 已提交
53 54 55 56 57 58
    unsigned long long get_inoctets() { return in_octets_;};
    unsigned long long get_octets() { return out_octets_;};
    std::chrono::system_clock::time_point get_nettime() { return net_time_;};
    void set_inoctets(unsigned long long value) { in_octets_ = value;};
    void set_outoctets(unsigned long long value) { out_octets_ = value;};
    void set_nettime() {net_time_ = std::chrono::system_clock::now();};
Y
fix  
yu yunfeng 已提交
59
    long long ParseLine(char* line);
Y
yu yunfeng 已提交
60 61 62 63
    unsigned long GetPhysicalMemory();
    unsigned long GetProcessUsedMemory();
    double MemoryPercent();
    double CPUPercent();
Y
yu yunfeng 已提交
64
    std::pair<unsigned long long , unsigned long long > Octets();
K
kun yu 已提交
65
    std::vector<unsigned long long> GPUMemoryTotal();
Y
yu yunfeng 已提交
66
    std::vector<unsigned long long> GPUMemoryUsed();
Y
yu yunfeng 已提交
67

K
kun yu 已提交
68 69
    std::vector<double> CPUCorePercent();
    std::vector<unsigned long long> getTotalCpuTime(std::vector<unsigned long long> &workTime);
K
kun yu 已提交
70 71
    std::vector<unsigned int> GPUTemperature();
    std::vector<float> CPUTemperature();
K
kun yu 已提交
72

Y
yu yunfeng 已提交
73 74 75 76 77
};

}
}
}