CernVM-FS  2.12.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 "swissknife.h"
9 
10 #include <pthread.h>
11 
12 #include <string>
13 
14 #include "catalog_traversal.h"
15 #include "sql.h"
16 #include "util/atomic.h"
17 
18 using namespace std; // NOLINT
19 
20 namespace swissknife {
21 
22 // Database class for storing repo statistics, the class design
23 // follows StatisticsDatabase's design
24 class FileStatsDatabase : public sqlite::Database<FileStatsDatabase> {
25  public:
26  bool CreateEmptyDatabase();
27 
28  // Following Store* functions return the primary key value of the
29  // inserted entry
30  int64_t StoreCatalog(int64_t num_entries, int64_t file_size);
31  int64_t StoreFile(int64_t catalog_id, int64_t object_id);
32  int64_t StoreObject(const void *hash, int hash_size, int64_t size);
33  int64_t StoreChunkedFile(int64_t catalog_id);
34  int64_t StoreChunk(const void *hash, int hash_size, int64_t size,
35  int64_t file_id);
36  int64_t StoreSymlink(int64_t length);
37  void InitStatements();
38  void DestroyStatements();
39 
40  static float kLatestSchema;
41  static unsigned kLatestSchemaRevision;
42 
43  protected:
51  FileStatsDatabase(const std::string &filename,
52  const OpenMode open_mode)
53  : sqlite::Database<FileStatsDatabase>(filename, open_mode) { }
54 };
55 
56 
57 class CommandFileStats : public Command {
58  public:
60  virtual std::string GetName() const { return "filestats"; }
61  virtual std::string GetDescription() const {
62  return "CernVM File System repository statistics exporter.";
63  }
64  virtual ParameterList GetParams() const;
65  int Main(const ArgumentList &args);
66 
67  protected:
68  string db_path_;
69  string tmp_db_path_;
71 
72  pthread_t thread_processing_;
75 
76  template <class ObjectFetcherT>
77  bool Run(ObjectFetcherT *object_fetcher);
78 
79  void CatalogCallback(const CatalogTraversalData<catalog::Catalog> &data);
80 
81  static void *MainProcessing(void *data);
82 
83  void ProcessCatalog(string db_path);
84 };
85 
86 } // namespace swissknife
87 
88 #endif // CVMFS_SWISSKNIFE_FILESTATS_H_
const std::string & filename() const
Definition: sql.h:148
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