• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021. 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 // pgpgin: Total number of kilobytes the system paged in from disk.
17 // pgpgout: Total number of kilobytes the system paged out to disk.
18 // see https://man7.org/linux/man-pages/man5/proc.5.html
19 
20 #ifndef DISKIO_DATA_PLUGIN_H
21 #define DISKIO_DATA_PLUGIN_H
22 
23 #include <fcntl.h>
24 #include <string>
25 #include <unistd.h>
26 
27 #include "diskio_plugin_config.pb.h"
28 #include "diskio_plugin_result.pb.h"
29 #include "logging.h"
30 #include "io_stats.h"
31 #include "plugin_module_api.h"
32 
33 enum ErrorType {
34     RET_NULL_ADDR,
35     RET_IVALID_PID,
36     RET_TGID_VALUE_NULL,
37     RET_FAIL = -1,
38     RET_SUCC = 0,
39 };
40 
41 class DiskioDataPlugin {
42 public:
43     DiskioDataPlugin();
44     ~DiskioDataPlugin();
45     int Start(const uint8_t* configData, uint32_t configSize);
46     int Report(uint8_t* configData, uint32_t configSize);
47     int ReportOptimize(RandomWriteCtx* randomWrite);
48     int Stop();
49 
50 private:
51     int32_t ReadFile(std::string& fileName);
52 
53     template <typename T> void SetTimestamp(T& diskioData);
54 
55     template <typename T> void SetDiskioData(T& diskioData, const char* pFile, uint32_t fileLen);
56 
57     template <typename T> void WriteDiskioData(T& diskioData);
58 
59     // for UT
SetPath(std::string path)60     void SetPath(std::string path)
61     {
62         path_ = path;
63     }
64 
65 private:
66     /* data */
67     void* buffer_;
68     std::string path_;
69     int32_t err_;
70 
71     int64_t prevRdSectorsKb_;
72     int64_t prevWrSectorsKb_;
73     struct timespec prevTimestamp_;
74     DiskioConfig protoConfig_;
75     std::shared_ptr<IoStats> ioEntry_;
76 };
77 
78 #endif
79