diff options
Diffstat (limited to 'analyzers/src/ofws')
-rw-r--r-- | analyzers/src/ofws/ofws_analyzer.cpp | 350 | ||||
-rw-r--r-- | analyzers/src/ofws/ofws_analyzer.h | 226 |
2 files changed, 0 insertions, 576 deletions
diff --git a/analyzers/src/ofws/ofws_analyzer.cpp b/analyzers/src/ofws/ofws_analyzer.cpp deleted file mode 100644 index a85371c..0000000 --- a/analyzers/src/ofws/ofws_analyzer.cpp +++ /dev/null @@ -1,350 +0,0 @@ -//------------------------------------------------------------------------------ -// Author: Dzianis Huznou -// Description: Overall File Working Set (OFWS) analyzer. Enumerate the overall set of files accessed by clients. -// Copyright (c) 2013 EPAM Systems -//------------------------------------------------------------------------------ -/* - This file is part of Nfstrace. - - Nfstrace is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, version 2 of the License. - - Nfstrace is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Nfstrace. If not, see <http://www.gnu.org/licenses/>. -*/ -//------------------------------------------------------------------------------ -#include <algorithm> -#include <vector> - -#include "ofws_analyzer.h" -//------------------------------------------------------------------------------ -OFWSAnalyzer::~OFWSAnalyzer() -{ - Iterator i = ofws_stat.begin(); - Iterator end = ofws_stat.end(); - for(; i != end;) - { - delete i->second; - i = ofws_stat.erase(i); - } -} - -void OFWSAnalyzer::getattr3(const RPCProcedure*, - const struct rpcgen::GETATTR3args* args, - const struct rpcgen::GETATTR3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object); - (*i->second).inc(ProcEnumNFS3::GETATTR); - } -} - -void OFWSAnalyzer::setattr3(const RPCProcedure*, - const struct rpcgen::SETATTR3args* args, - const struct rpcgen::SETATTR3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object); - (*i->second).inc(ProcEnumNFS3::SETATTR); - } -} - -void OFWSAnalyzer::lookup3(const RPCProcedure*, - const struct rpcgen::LOOKUP3args*, - const struct rpcgen::LOOKUP3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(res->LOOKUP3res_u.resok.object); - (*i->second).inc(ProcEnumNFS3::LOOKUP); - } -} - -void OFWSAnalyzer::access3(const struct RPCProcedure*, - const struct rpcgen::ACCESS3args* args, - const struct rpcgen::ACCESS3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object); - (*i->second).inc(ProcEnumNFS3::ACCESS); - } -} - -void OFWSAnalyzer::readlink3(const struct RPCProcedure*, - const struct rpcgen::READLINK3args* args, - const struct rpcgen::READLINK3res* res) -{ - if(res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->symlink); - (*i->second).inc(ProcEnumNFS3::READLINK); - } -} - -void OFWSAnalyzer::read3(const struct RPCProcedure*, - const struct rpcgen::READ3args* args, - const struct rpcgen::READ3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->file); - (*i->second).inc(ProcEnumNFS3::READ); - } -} - -void OFWSAnalyzer::write3(const struct RPCProcedure*, - const struct rpcgen::WRITE3args* args, - const struct rpcgen::WRITE3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->file); - (*i->second).inc(ProcEnumNFS3::WRITE); - } -} - -void OFWSAnalyzer::create3(const struct RPCProcedure*, - const struct rpcgen::CREATE3args*, - const struct rpcgen::CREATE3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - if(res->CREATE3res_u.resok.obj.handle_follows) - { - Iterator i = find_or_create_op_counter(res->CREATE3res_u.resok.obj.post_op_fh3_u.handle); - (*i->second).inc(ProcEnumNFS3::CREATE); - } - } -} - -void OFWSAnalyzer::mkdir3(const struct RPCProcedure*, - const struct rpcgen::MKDIR3args*, - const struct rpcgen::MKDIR3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - if(res->MKDIR3res_u.resok.obj.handle_follows) - { - Iterator i = find_or_create_op_counter(res->MKDIR3res_u.resok.obj.post_op_fh3_u.handle); - (*i->second).inc(ProcEnumNFS3::MKDIR); - } - } -} - -void OFWSAnalyzer::symlink3(const struct RPCProcedure*, - const struct rpcgen::SYMLINK3args*, - const struct rpcgen::SYMLINK3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - if(res->SYMLINK3res_u.resok.obj.handle_follows) - { - Iterator i = find_or_create_op_counter(res->SYMLINK3res_u.resok.obj.post_op_fh3_u.handle); - (*i->second).inc(ProcEnumNFS3::SYMLINK); - } - } -} - -void OFWSAnalyzer::mknod3(const struct RPCProcedure*, - const struct rpcgen::MKNOD3args*, - const struct rpcgen::MKNOD3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - if(res->MKNOD3res_u.resok.obj.handle_follows) - { - Iterator i = find_or_create_op_counter(res->MKNOD3res_u.resok.obj.post_op_fh3_u.handle); - (*i->second).inc(ProcEnumNFS3::MKNOD); - } - } -} - -void OFWSAnalyzer::remove3(const struct RPCProcedure*, - const struct rpcgen::REMOVE3args* args, - const struct rpcgen::REMOVE3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object.dir); - (*i->second).inc(ProcEnumNFS3::REMOVE); - } -} - -void OFWSAnalyzer::rmdir3(const struct RPCProcedure*, - const struct rpcgen::RMDIR3args* args, - const struct rpcgen::RMDIR3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object.dir); - (*i->second).inc(ProcEnumNFS3::RMDIR); - } -} - -void OFWSAnalyzer::rename3(const struct RPCProcedure*, - const struct rpcgen::RENAME3args* args, - const struct rpcgen::RENAME3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->from.dir); - (*i->second).inc(ProcEnumNFS3::RENAME); - } -} - -void OFWSAnalyzer::link3(const struct RPCProcedure*, - const struct rpcgen::LINK3args* args, - const struct rpcgen::LINK3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->file); - (*i->second).inc(ProcEnumNFS3::LINK); - } -} - -void OFWSAnalyzer::readdir3(const struct RPCProcedure*, - const struct rpcgen::READDIR3args* args, - const struct rpcgen::READDIR3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->dir); - (*i->second).inc(ProcEnumNFS3::READDIR); - } -} - -void OFWSAnalyzer::readdirplus3(const struct RPCProcedure*, - const struct rpcgen::READDIRPLUS3args* args, - const struct rpcgen::READDIRPLUS3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->dir); - (*i->second).inc(ProcEnumNFS3::READDIRPLUS); - } -} - -void OFWSAnalyzer::fsstat3(const struct RPCProcedure*, - const struct rpcgen::FSSTAT3args* args, - const struct rpcgen::FSSTAT3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->fsroot); - (*i->second).inc(ProcEnumNFS3::FSSTAT); - } -} - -void OFWSAnalyzer::fsinfo3(const struct RPCProcedure*, - const struct rpcgen::FSINFO3args* args, - const struct rpcgen::FSINFO3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->fsroot); - (*i->second).inc(ProcEnumNFS3::FSINFO); - } -} - -void OFWSAnalyzer::pathconf3(const struct RPCProcedure*, - const struct rpcgen::PATHCONF3args* args, - const struct rpcgen::PATHCONF3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->object); - (*i->second).inc(ProcEnumNFS3::PATHCONF); - } -} - -void OFWSAnalyzer::commit3(const struct RPCProcedure*, - const struct rpcgen::COMMIT3args* args, - const struct rpcgen::COMMIT3res* res) -{ - if(res && res->status == rpcgen::nfsstat3::NFS3_OK) - { - Iterator i = find_or_create_op_counter(args->file); - (*i->second).inc(ProcEnumNFS3::COMMIT); - } -} - -void OFWSAnalyzer::flush_statistics() -{ - uint32_t size = ofws_stat.size(); - std::vector< Iterator > v(size); - Iterator i = ofws_stat.begin(); - Iterator end = ofws_stat.end(); - for(uint32_t j = 0; i != end; ++i, ++j) - { - v[j] = i; - } - std::sort(v.begin(), v.end(), iterator_comp); - - out << "### Overall File Working Set (OFWS) analyzer ###" << std::endl; - out << "Total number of files accessed: " << size << std::endl; - out << "FileHandle" << ",NFS Ops"; - for(int32_t j = 0; j < ProcEnumNFS3::count; ++j) - { - out << ',' << print_nfs3_procedures(static_cast<ProcEnumNFS3::NFSProcedure>(j)); - } - out << '\n'; - - for(uint32_t i = 0; i != size; ++i) - { - Iterator& iterator = v[i]; - const OpCounter* opcounter = iterator->second; - - out << iterator->first << ',' << opcounter->get_total(); - for(int32_t j = 0; j < ProcEnumNFS3::count; ++j) - { - out << ',' << (*opcounter)[j]; - } - out << '\n'; - } -} - -OFWSAnalyzer::Iterator OFWSAnalyzer::find_or_create_op_counter(const rpcgen::nfs_fh3& key) -{ - Iterator i = ofws_stat.find(key); - if(i == ofws_stat.end()) - { - Inserted ins = ofws_stat.insert(Pair(key, new OpCounter())); - if(ins.second == false) - throw int(); - i = ins.first; - } - return i; -} - -extern "C" -{ - -const char* usage() -{ - return "Arguments aren't supported. TODO: add description of OFWS Analyser"; -} - -IAnalyzer* create(const char* /*opts*/) -{ - return new OFWSAnalyzer(); -} - -void destroy(IAnalyzer* instance) -{ - delete instance; -} - -NST_PLUGIN_ENTRY_POINTS (&usage, &create, &destroy) - -} -//------------------------------------------------------------------------------ diff --git a/analyzers/src/ofws/ofws_analyzer.h b/analyzers/src/ofws/ofws_analyzer.h deleted file mode 100644 index 1c1beb5..0000000 --- a/analyzers/src/ofws/ofws_analyzer.h +++ /dev/null @@ -1,226 +0,0 @@ -//------------------------------------------------------------------------------ -// Author: Dzianis Huznou -// Description: Overall File Working Set (OFWS) analyzer. Enumerate the overall set of files accessed by clients. -// Copyright (c) 2013 EPAM Systems -//------------------------------------------------------------------------------ -/* - This file is part of Nfstrace. - - Nfstrace is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, version 2 of the License. - - Nfstrace is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Nfstrace. If not, see <http://www.gnu.org/licenses/>. -*/ -//------------------------------------------------------------------------------ -#ifndef OFWS_ANALYZER_H -#define OFWS_ANALYZER_H -//------------------------------------------------------------------------------ -#include <cstdint> -#include <iomanip> -#include <ostream> -#include <cstring> -#include <unordered_map> - -#include <api/plugin_api.h> -//------------------------------------------------------------------------------ -struct FH -{ - uint32_t len {}; - char data[rpcgen::NFS3_FHSIZE] {}; - - struct FH_Eq - { - bool operator()(const FH& a, const FH& b) const; - }; - struct FH_Hash - { - int operator()(const FH& fh) const; - }; - - inline FH(const rpcgen::nfs_fh3& obj) - { - len = obj.data.data_len; - memcpy(data, obj.data.data_val, len); - } - inline FH(const FH& obj) - { - len = obj.len; - memcpy(data, obj.data, len); - } - std::string to_string() const; - - friend std::ostream& operator<<(std::ostream& out, const FH& obj); - - -private: - static inline char to_char(uint8_t hex) - { - if(hex < 0xA) - return hex + '0'; - else - return hex + 'a' - 0xA; - } -}; - -inline int FH::FH_Hash::operator()(const FH& fh) const -{ - int hash = 0; - for(uint32_t i = 0; i < fh.len; ++i) - hash += fh.data[i]; - return hash; -} - -inline bool FH::FH_Eq::operator()(const FH& a, const FH& b) const -{ - if(a.len != b.len) - return false; - - for(uint32_t i = 0; i < a.len; ++i) - if(a.data[i] != b.data[i]) - return false; - return true; -} - -inline std::string FH::to_string() const -{ - std::string str; - str.reserve(rpcgen::NFS3_FHSIZE * 2 + 1); // One byte holds two symbols. - for(uint32_t i = 0; i < len; ++i) - { - str += to_char((data[i] >> 4) & 0xf); - str += to_char(data[i] & 0xf); - } - return str; -} - -inline std::ostream& operator<<(std::ostream& out, const FH& fh) -{ - print_nfs_fh(out, fh.data, fh.len); - return out; -} - -class OFWSAnalyzer : public IAnalyzer -{ - class OpCounter - { - public: - inline OpCounter() : total{0} - { - std::memset(counters, 0, sizeof(counters)); - } - inline ~OpCounter() {} - inline void inc(ProcEnumNFS3::NFSProcedure op, uint32_t size = 1) - { - total += size; - counters[op] += size; - } - inline uint64_t get_total() const { return total; } - inline uint32_t operator[](uint32_t op) const { return counters[op]; } - private: - OpCounter(const OpCounter&); - void operator=(const OpCounter&); - - uint32_t counters[ProcEnumNFS3::count]; - uint64_t total; - }; - - typedef std::unordered_map<FH, OpCounter*, FH::FH_Hash, FH::FH_Eq> OFWS; - typedef OFWS::value_type Pair; - typedef OFWS::iterator Iterator; - typedef OFWS::const_iterator ConstIterator; - typedef std::pair<Iterator, bool> Inserted; - - struct Iterator_Comp - { - inline bool operator()(const Iterator& a, const Iterator& b) const - { - return (a->second->get_total() < b->second->get_total()); - } - } iterator_comp; - -public: - inline OFWSAnalyzer():out(std::cout) {} - virtual ~OFWSAnalyzer(); - - void getattr3(const struct RPCProcedure* proc, - const struct rpcgen::GETATTR3args* args, - const struct rpcgen::GETATTR3res* res) override final; - void setattr3(const struct RPCProcedure* proc, - const struct rpcgen::SETATTR3args* args, - const struct rpcgen::SETATTR3res* res) override final; - void lookup3(const struct RPCProcedure* proc, - const struct rpcgen::LOOKUP3args* args, - const struct rpcgen::LOOKUP3res* res) override final; - void access3(const struct RPCProcedure* proc, - const struct rpcgen::ACCESS3args* args, - const struct rpcgen::ACCESS3res* res) override final; - void readlink3(const struct RPCProcedure* proc, - const struct rpcgen::READLINK3args* args, - const struct rpcgen::READLINK3res* res) override final; - void read3(const struct RPCProcedure* proc, - const struct rpcgen::READ3args* args, - const struct rpcgen::READ3res* res) override final; - void write3(const struct RPCProcedure* proc, - const struct rpcgen::WRITE3args* args, - const struct rpcgen::WRITE3res* res) override final; - void create3(const struct RPCProcedure* proc, - const struct rpcgen::CREATE3args* args, - const struct rpcgen::CREATE3res* res) override final; - void mkdir3(const struct RPCProcedure* proc, - const struct rpcgen::MKDIR3args* args, - const struct rpcgen::MKDIR3res* res) override final; - void symlink3(const struct RPCProcedure* proc, - const struct rpcgen::SYMLINK3args* args, - const struct rpcgen::SYMLINK3res* res) override final; - void mknod3(const struct RPCProcedure* proc, - const struct rpcgen::MKNOD3args* args, - const struct rpcgen::MKNOD3res* res) override final; - void remove3(const struct RPCProcedure* proc, - const struct rpcgen::REMOVE3args* args, - const struct rpcgen::REMOVE3res* res) override final; - void rmdir3(const struct RPCProcedure* proc, - const struct rpcgen::RMDIR3args* args, - const struct rpcgen::RMDIR3res* res) override final; - void rename3(const struct RPCProcedure* proc, - const struct rpcgen::RENAME3args* args, - const struct rpcgen::RENAME3res* res) override final; - void link3(const struct RPCProcedure* proc, - const struct rpcgen::LINK3args* args, - const struct rpcgen::LINK3res* res) override final; - void readdir3(const struct RPCProcedure* proc, - const struct rpcgen::READDIR3args* args, - const struct rpcgen::READDIR3res* res) override final; - void readdirplus3(const struct RPCProcedure* proc, - const struct rpcgen::READDIRPLUS3args* args, - const struct rpcgen::READDIRPLUS3res* res) override final; - void fsstat3(const struct RPCProcedure* proc, - const struct rpcgen::FSSTAT3args* args, - const struct rpcgen::FSSTAT3res* res) override final; - void fsinfo3(const struct RPCProcedure* proc, - const struct rpcgen::FSINFO3args* args, - const struct rpcgen::FSINFO3res* res) override final; - void pathconf3(const struct RPCProcedure* proc, - const struct rpcgen::PATHCONF3args* args, - const struct rpcgen::PATHCONF3res* res) override final; - void commit3(const struct RPCProcedure* proc, - const struct rpcgen::COMMIT3args* args, - const struct rpcgen::COMMIT3res* res) override final; - - virtual void flush_statistics(); - -private: - Iterator find_or_create_op_counter(const rpcgen::nfs_fh3& key); - - OFWS ofws_stat; - std::ostream& out; -}; -//------------------------------------------------------------------------------ -#endif//OFWS_ANALYZER_H -//------------------------------------------------------------------------------ |