Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:22:24

0001 
0002 #ifndef Utilities_StorageFactory_StatisticsSenderService_H
0003 #define Utilities_StorageFactory_StatisticsSenderService_H
0004 
0005 #include <string>
0006 #include <sstream>
0007 #include <atomic>
0008 #include <mutex>
0009 #include <oneapi/tbb/concurrent_unordered_map.h>
0010 #include "FWCore/Utilities/interface/InputType.h"
0011 
0012 namespace edm {
0013 
0014   class ParameterSet;
0015   class ActivityRegistry;
0016 
0017   namespace storage {
0018 
0019     class StatisticsSenderService {
0020     public:
0021       StatisticsSenderService(edm::ParameterSet const& pset, edm::ActivityRegistry& ar);
0022 
0023       void setSize(const std::string& urlOrLfn, size_t size);
0024       void setCurrentServer(const std::string& urlOrLfn, const std::string& servername);
0025       static const char* getJobID();
0026       static bool getX509Subject(std::string&);
0027 
0028       void openingFile(std::string const& lfn, edm::InputType type, size_t size = -1);
0029       void closedFile(std::string const& lfn, bool usedFallback);
0030 
0031     private:
0032       void filePostCloseEvent(std::string const& lfn);
0033 
0034       std::string const* matchedLfn(std::string const& iURL);  //updates its internal cache
0035       class FileStatistics {
0036       public:
0037         FileStatistics();
0038         void fillUDP(std::ostringstream& os) const;
0039         void update();
0040 
0041       private:
0042         ssize_t m_read_single_operations;
0043         ssize_t m_read_single_bytes;
0044         ssize_t m_read_single_square;
0045         ssize_t m_read_vector_operations;
0046         ssize_t m_read_vector_bytes;
0047         ssize_t m_read_vector_square;
0048         ssize_t m_read_vector_count_sum;
0049         ssize_t m_read_vector_count_square;
0050         time_t m_start_time;
0051       };
0052 
0053       struct FileInfo {
0054         explicit FileInfo(std::string const& iLFN, edm::InputType);
0055 
0056         FileInfo(FileInfo&& iInfo)
0057             : m_filelfn(std::move(iInfo.m_filelfn)),
0058               m_serverhost(std::move(iInfo.m_serverhost)),
0059               m_serverdomain(std::move(iInfo.m_serverdomain)),
0060               m_type(iInfo.m_type),
0061               m_size(iInfo.m_size.load()),
0062               m_id(iInfo.m_id),
0063               m_openCount(iInfo.m_openCount.load()) {}
0064         std::string m_filelfn;
0065         std::string m_serverhost;
0066         std::string m_serverdomain;
0067         edm::InputType m_type;
0068         std::atomic<ssize_t> m_size;
0069         size_t m_id;  //from m_counter
0070         std::atomic<int> m_openCount;
0071       };
0072 
0073       void determineHostnames();
0074       void fillUDP(const std::string& site, const FileInfo& fileinfo, bool, std::string&) const;
0075       void cleanupOldFiles();
0076 
0077       std::string m_clienthost;
0078       std::string m_clientdomain;
0079       oneapi::tbb::concurrent_unordered_map<std::string, FileInfo> m_lfnToFileInfo;
0080       oneapi::tbb::concurrent_unordered_map<std::string, std::string> m_urlToLfn;
0081       FileStatistics m_filestats;
0082       std::string m_guid;
0083       size_t m_counter;
0084       std::string m_userdn;
0085       std::mutex m_servermutex;
0086       const bool m_debug;
0087     };
0088 
0089   }  // namespace storage
0090 }  // namespace edm
0091 
0092 #endif