• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
32 enum ErrorType {
33     RET_NULL_ADDR,
34     RET_IVALID_PID,
35     RET_TGID_VALUE_NULL,
36     RET_FAIL = -1,
37     RET_SUCC = 0,
38 };
39 
40 class DiskioDataPlugin {
41 public:
42     DiskioDataPlugin();
43     ~DiskioDataPlugin();
44     int Start(const uint8_t* configData, uint32_t configSize);
45     int Report(uint8_t* configData, uint32_t configSize);
46     int Stop();
47 
48 private:
49     int32_t ReadFile(std::string& fileName);
50     void SetTimestamp(CollectTimeStamp& prevTimestamp, CollectTimeStamp& timestamp);
51     void SetDiskioData(DiskioData& diskioData, const char* pFile, uint32_t fileLen);
52     void WriteDiskioData(DiskioData& diskioData);
53 
54     // for UT
SetPath(std::string path)55     void SetPath(std::string path)
56     {
57         path_ = path;
58     }
59 
60 private:
61     /* data */
62     void* buffer_;
63     std::string path_;
64     int32_t err_;
65 
66     int64_t prevRdSectorsKb_;
67     int64_t prevWrSectorsKb_;
68     CollectTimeStamp prevTimestamp_;
69     DiskioConfig protoConfig_;
70     std::shared_ptr<IoStats> ioEntry_;
71 };
72 
73 #endif
74