CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_filestats.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_SWISSKNIFE_FILESTATS_H_
6 #define CVMFS_SWISSKNIFE_FILESTATS_H_
7 
8 #include <pthread.h>
9 
10 #include <string>
11 
12 #include "catalog_traversal.h"
13 #include "sql.h"
14 #include "swissknife.h"
15 #include "util/atomic.h"
16 
17 using namespace std; // NOLINT
18 
19 namespace swissknife {
20 
21 // Database class for storing repo statistics, the class design
22 // follows StatisticsDatabase's design
23 class FileStatsDatabase : public sqlite::Database<FileStatsDatabase> {
24  public:
25  bool CreateEmptyDatabase();
26 
27  // Following Store* functions return the primary key value of the
28  // inserted entry
29  int64_t StoreCatalog(int64_t num_entries, int64_t file_size);
30  int64_t StoreFile(int64_t catalog_id, int64_t object_id);
31  int64_t StoreObject(const void *hash, int hash_size, int64_t size);
32  int64_t StoreChunkedFile(int64_t catalog_id);
33  int64_t StoreChunk(const void *hash, int hash_size, int64_t size,
34  int64_t file_id);
35  int64_t StoreSymlink(int64_t length);
36  void InitStatements();
37  void DestroyStatements();
38 
39  static float kLatestSchema;
40  static unsigned kLatestSchemaRevision;
41 
42  protected:
50  FileStatsDatabase(const std::string &filename, const OpenMode open_mode)
51  : sqlite::Database<FileStatsDatabase>(filename, open_mode) { }
52 };
53 
54 
55 class CommandFileStats : public Command {
56  public:
58  virtual std::string GetName() const { return "filestats"; }
59  virtual std::string GetDescription() const {
60  return "CernVM File System repository statistics exporter.";
61  }
62  virtual ParameterList GetParams() const;
63  int Main(const ArgumentList &args);
64 
65  protected:
66  string db_path_;
67  string tmp_db_path_;
69 
70  pthread_t thread_processing_;
73 
74  template<class ObjectFetcherT>
75  bool Run(ObjectFetcherT *object_fetcher);
76 
77  void CatalogCallback(const CatalogTraversalData<catalog::Catalog> &data);
78 
79  static void *MainProcessing(void *data);
80 
81  void ProcessCatalog(string db_path);
82 };
83 
84 } // namespace swissknife
85 
86 #endif // CVMFS_SWISSKNIFE_FILESTATS_H_
const std::string & filename() const
Definition: sql.h:146
std::vector< Parameter > ParameterList
Definition: swissknife.h:71
Database(const std::string &filename, const OpenMode open_mode)
Definition: sql_impl.h:21
int32_t atomic_int32
Definition: atomic.h:17
virtual std::string GetDescription() const
virtual std::string GetName() const
FileStatsDatabase(const std::string &filename, const OpenMode open_mode)
std::map< char, SharedPtr< std::string > > ArgumentList
Definition: swissknife.h:72
static void size_t size
Definition: smalloc.h:54