123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #ifndef __MAS_PFM_MONITOR_H
- #define __MAS_PFM_MONITOR_H
- #include "DBMgr.h"
- #include "FileHelper.h"
- #include "Locks.h"
- #include "Thread.h"
- #include "SysUtils.h"
- #include "nvml.h"
- NAMESPACE_MAS_BEGIN
- #define MASPFMMONITOR PerformanceMonitor::GetInstance()
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLINIT)(void);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLSHUTDOWN)(void);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLDEVICEGETCOUNT)(TZ_Uint32 *);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLDEVICEGETHANDLEBYINDEX)(TZ_Uint32 index,
- nvmlDevice_t *device);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLDEVICEGETMEMORYINFO)(nvmlDevice_t device,
- nvmlMemory_t *memory);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLDEVICEGETUTILIZATIONRATE)(nvmlDevice_t device,
- nvmlUtilization_t *utilization);
- typedef nvmlReturn_t (DECLDIR * GPUPERF_NVMLDEVICEGETTEMPERATURE)(nvmlDevice_t device,
- nvmlTemperatureSensors_t sensorType, unsigned int *temp);
- // 系统GPU情况
- struct SysGPUPerf
- {
- TZ_Uint32 gpuIndex;
- TZ_Uint32 gpuUseRate;
- TZ_Uint64 memTotal;
- TZ_Uint64 memFree;
- TZ_Uint64 memUsed;
- };
- class PerformanceMonitor : tzc::OSThread {
- public:
- static PerformanceMonitor * GetInstance();
- static void DestoryInstance();
- TZ_INT Initialize();
- TZ_INT Dispose();
- /* 设置采集时间间隔 */
- void SetIntervalTime(TZ_INT time);
- private:
- PerformanceMonitor();
- ~PerformanceMonitor();
-
- void initData();
- /* 功能:按设定间隔采集系统性能数据,并写入数据库 */
- virtual void Entry();
- /* CPU占用率 */
- void collectCPUData();
- /* 内存占用率 */
- void collectMemData();
- /* 磁盘IO */
- void collectDiskIOData();
- /* 网络带宽占用率 */
- void collectBandWidthRate();
- /* CPU信息 */
- void collectCPUInfo();
- /* 网络连接信息 */
- void collectNetworkInfo();
- /* 磁盘使用率 */
- void collectDiskInfo();
- /* GPU信息 */
- void collectGPUInfo();
- void collectGPUData();
- void clearGPUperf();
- template<typename T>
- TZ_INT loadNvmlFunc(T & funcPoint, const std::string & funcName);
- private:
- TZ_BOOL m_inited;
- TZ_INT m_timeCnt;
- TZ_INT m_intervalTime; /* 自定义采集频率 */
- GPUPERF_NVMLINIT m_fNvmlInit;
- GPUPERF_NVMLSHUTDOWN m_fNvmlShutdown;
- GPUPERF_NVMLDEVICEGETCOUNT m_fNvmlDeviceGetCount;
- GPUPERF_NVMLDEVICEGETHANDLEBYINDEX m_fNvmlDeviceGetHandleByIndex;
- GPUPERF_NVMLDEVICEGETMEMORYINFO m_fNvmlDeviceGetMemoryInfo;
- GPUPERF_NVMLDEVICEGETUTILIZATIONRATE m_fNvmlDeviceGetUtilizationRate;
- GPUPERF_NVMLDEVICEGETTEMPERATURE m_fNvmlDeviceGetTemperature;
-
- TZ_DLLHD m_hdLib;
- TblPerformanceRecordItem m_tbl;
- /* CPU占用率参数 */
- SysStatInfo m_cpuDataInfo;
- TZ_DOUBLE m_cpuUse;
- /* 内存占用率参数 */
- SysMemInfo m_memDataInfo;
- /* 磁盘IO参数 */
- std::list<SysDiskStatInfo> m_diskDataList;
- TZ_DOUBLE m_readSpeed;
- TZ_DOUBLE m_writeSpeed;
- /* 网络带宽占用率参数 */
- std::list<SysNetBandInfo> m_netDataList;
- std::map<std::string, TZ_DOUBLE> m_bandWidthInfoMap;
- /* 系统信息参数 */
- SystemInfo m_sysInfo;
- std::list<InterfaceInfo> m_interFaces;
- /* CPU信息参数 */
- CPUInfo m_cpuInfo;
- /* 网络接口信息参数(端口使用情况) */
- std::list<NetstatInfo> m_netInfos;
- /* 磁盘信息参数 */
- std::list<DiskstatInfo> m_diskInfos;
- /* GPU信息参数 */
- std::string m_GPUName;
- std::vector<SysGPUPerf> m_vGPUPerf;
- tzc::Mutex m_lockGPUPerf;
- static PerformanceMonitor * _ins;
- static tzc::Mutex _insLock;
- };
- template<typename T>
- TZ_INT PerformanceMonitor::loadNvmlFunc(T & funcPoint, const std::string & funcName)
- {
- if (m_hdLib == nullptr)
- {
- TZLogWarn("The hd Lib is nullptr");
- return MEC_FAILED;
- }
- TZ_DLLHD hdFunc = tzc::SysUtils::GetSymbol(m_hdLib, funcName.c_str());
- if (hdFunc == nullptr)
- {
- TZLogWarn("The handle of function is nullptr:%s", funcName.c_str());
- return MEC_FAILED;
- }
- funcPoint = (T)(hdFunc);
- TZLogInfo("load function success!!!:%s", funcName.c_str());
- return MEC_OK;
- }
- NAMESPACE_MAS_END
- #endif
|