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 "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: |
44 |
|
|
sqlite::Sql *query_insert_catalog; |
45 |
|
|
sqlite::Sql *query_insert_object; |
46 |
|
|
sqlite::Sql *query_insert_file; |
47 |
|
|
sqlite::Sql *query_insert_file_object; |
48 |
|
|
sqlite::Sql *query_insert_symlink; |
49 |
|
|
sqlite::Sql *query_lookup_object; |
50 |
|
|
friend class sqlite::Database<FileStatsDatabase>; |
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: |
59 |
|
✗ |
~CommandFileStats() {} |
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_; |
70 |
|
|
FileStatsDatabase* db_; |
71 |
|
|
|
72 |
|
|
pthread_t thread_processing_; |
73 |
|
|
atomic_int32 num_downloaded_; |
74 |
|
|
atomic_int32 finished_; |
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_ |
89 |
|
|
|