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