1/*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef GPU_DATA_PLUGIN_H
17#define GPU_DATA_PLUGIN_H
18
19#include <dirent.h>
20#include <fcntl.h>
21#include <string>
22#include <unistd.h>
23#include <fstream>
24#include <iostream>
25
26#include "gpu_plugin_config.pb.h"
27#include "gpu_plugin_result.pb.h"
28#include "logging.h"
29#include "plugin_module_api.h"
30
31enum ErrorType {
32    RET_NULL_ADDR = -2,
33    RET_FAIL = -1,
34    RET_SUCC = 0,
35};
36
37class GpuDataPlugin {
38public:
39    GpuDataPlugin() = default;
40    ~GpuDataPlugin() = default;
41    int Start(const uint8_t* configData, uint32_t configSize);
42    int Report(uint8_t* data, uint32_t dataSize);
43    int ReportOptimize(RandomWriteCtx* randomWrite);
44    int Stop();
45
46private:
47    int ReadFile();
48    template <typename T> void WriteGpuDataInfo(T& gpuData);
49
50private:
51    GpuConfig protoConfig_;
52    int pid_ = -1;
53    std::ifstream file_;
54};
55
56#endif
57