106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci// pgpgin: Total number of kilobytes the system paged in from disk. 1706f6ba60Sopenharmony_ci// pgpgout: Total number of kilobytes the system paged out to disk. 1806f6ba60Sopenharmony_ci// see https://man7.org/linux/man-pages/man5/proc.5.html 1906f6ba60Sopenharmony_ci 2006f6ba60Sopenharmony_ci#ifndef DISKIO_DATA_PLUGIN_H 2106f6ba60Sopenharmony_ci#define DISKIO_DATA_PLUGIN_H 2206f6ba60Sopenharmony_ci 2306f6ba60Sopenharmony_ci#include <fcntl.h> 2406f6ba60Sopenharmony_ci#include <string> 2506f6ba60Sopenharmony_ci#include <unistd.h> 2606f6ba60Sopenharmony_ci 2706f6ba60Sopenharmony_ci#include "diskio_plugin_config.pb.h" 2806f6ba60Sopenharmony_ci#include "diskio_plugin_result.pb.h" 2906f6ba60Sopenharmony_ci#include "logging.h" 3006f6ba60Sopenharmony_ci#include "io_stats.h" 3106f6ba60Sopenharmony_ci#include "plugin_module_api.h" 3206f6ba60Sopenharmony_ci 3306f6ba60Sopenharmony_cienum ErrorType { 3406f6ba60Sopenharmony_ci RET_NULL_ADDR, 3506f6ba60Sopenharmony_ci RET_IVALID_PID, 3606f6ba60Sopenharmony_ci RET_TGID_VALUE_NULL, 3706f6ba60Sopenharmony_ci RET_FAIL = -1, 3806f6ba60Sopenharmony_ci RET_SUCC = 0, 3906f6ba60Sopenharmony_ci}; 4006f6ba60Sopenharmony_ci 4106f6ba60Sopenharmony_ciclass DiskioDataPlugin { 4206f6ba60Sopenharmony_cipublic: 4306f6ba60Sopenharmony_ci DiskioDataPlugin(); 4406f6ba60Sopenharmony_ci ~DiskioDataPlugin(); 4506f6ba60Sopenharmony_ci int Start(const uint8_t* configData, uint32_t configSize); 4606f6ba60Sopenharmony_ci int Report(uint8_t* configData, uint32_t configSize); 4706f6ba60Sopenharmony_ci int ReportOptimize(RandomWriteCtx* randomWrite); 4806f6ba60Sopenharmony_ci int Stop(); 4906f6ba60Sopenharmony_ci 5006f6ba60Sopenharmony_ciprivate: 5106f6ba60Sopenharmony_ci int32_t ReadFile(std::string& fileName); 5206f6ba60Sopenharmony_ci 5306f6ba60Sopenharmony_ci template <typename T> void SetTimestamp(T& diskioData); 5406f6ba60Sopenharmony_ci 5506f6ba60Sopenharmony_ci template <typename T> void SetDiskioData(T& diskioData, const char* pFile, uint32_t fileLen); 5606f6ba60Sopenharmony_ci 5706f6ba60Sopenharmony_ci template <typename T> void WriteDiskioData(T& diskioData); 5806f6ba60Sopenharmony_ci 5906f6ba60Sopenharmony_ci // for UT 6006f6ba60Sopenharmony_ci void SetPath(std::string path) 6106f6ba60Sopenharmony_ci { 6206f6ba60Sopenharmony_ci path_ = path; 6306f6ba60Sopenharmony_ci } 6406f6ba60Sopenharmony_ci 6506f6ba60Sopenharmony_ciprivate: 6606f6ba60Sopenharmony_ci /* data */ 6706f6ba60Sopenharmony_ci void* buffer_; 6806f6ba60Sopenharmony_ci std::string path_; 6906f6ba60Sopenharmony_ci int32_t err_; 7006f6ba60Sopenharmony_ci 7106f6ba60Sopenharmony_ci int64_t prevRdSectorsKb_; 7206f6ba60Sopenharmony_ci int64_t prevWrSectorsKb_; 7306f6ba60Sopenharmony_ci struct timespec prevTimestamp_; 7406f6ba60Sopenharmony_ci DiskioConfig protoConfig_; 7506f6ba60Sopenharmony_ci std::shared_ptr<IoStats> ioEntry_; 7606f6ba60Sopenharmony_ci}; 7706f6ba60Sopenharmony_ci 7806f6ba60Sopenharmony_ci#endif 79