Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
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: |
43 |
|
|
sqlite::Sql *query_insert_catalog; |
44 |
|
|
sqlite::Sql *query_insert_object; |
45 |
|
|
sqlite::Sql *query_insert_file; |
46 |
|
|
sqlite::Sql *query_insert_file_object; |
47 |
|
|
sqlite::Sql *query_insert_symlink; |
48 |
|
|
sqlite::Sql *query_lookup_object; |
49 |
|
|
friend class sqlite::Database<FileStatsDatabase>; |
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: |
57 |
|
✗ |
~CommandFileStats() { } |
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_; |
68 |
|
|
FileStatsDatabase *db_; |
69 |
|
|
|
70 |
|
|
pthread_t thread_processing_; |
71 |
|
|
atomic_int32 num_downloaded_; |
72 |
|
|
atomic_int32 finished_; |
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_ |
87 |
|
|
|