1 // Copyright (C) 2010 and later by various people
2 // see monotone commit logs for details and authors
3 //
4 // This program is made available under the GNU GPL version 2.0 or
5 // greater. See the accompanying file COPYING for details.
6 //
7 // This program is distributed WITHOUT ANY WARRANTY; without even the
8 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 // PURPOSE.
10
11 #include "base.hh"
12 #include "cache_logger.hh"
13
14 #include <fstream>
15
16 using std::ofstream;
17 using std::endl;
18 using std::string;
19
20 class cache_logger_impl
21 {
22 public:
23 ofstream stream;
24
cache_logger_impl(string const & filename)25 explicit cache_logger_impl(string const & filename)
26 : stream(filename.c_str())
27 { }
28 };
29
cache_logger(string const & filename,int max_size)30 cache_logger::cache_logger(string const & filename, int max_size)
31 : max_size(max_size)
32 {
33 if (!filename.empty())
34 {
35 _impl.reset(new cache_logger_impl(filename));
36 }
37 }
38
log_exists(bool exists,int position,int item_count,int est_size) const39 void cache_logger::log_exists(bool exists, int position,
40 int item_count, int est_size) const
41 {
42 if (_impl)
43 {
44 _impl->stream << "Exists: " << (exists?"ok":"missing")
45 << "; position: " << position
46 << "; count: " << item_count
47 << "; size: " << est_size << " of " << max_size
48 << endl;
49 }
50 }
51
log_touch(bool exists,int position,int item_count,int est_size) const52 void cache_logger::log_touch(bool exists, int position,
53 int item_count, int est_size) const
54 {
55 if (_impl)
56 {
57 _impl->stream << "Touch: " << (exists?"ok":"missing")
58 << "; position: " << position
59 << "; count: " << item_count
60 << "; size: " << est_size << " of " << max_size
61 << endl;
62 }
63 }
64
log_fetch(bool exists,int position,int item_count,int est_size) const65 void cache_logger::log_fetch(bool exists, int position,
66 int item_count, int est_size) const
67 {
68 if (_impl)
69 {
70 _impl->stream << "Fetch: " << (exists?"ok":"missing")
71 << "; position: " << position
72 << "; count: " << item_count
73 << "; size: " << est_size << " of " << max_size
74 << endl;
75 }
76 }
77
log_insert(int items_removed,int item_count,int est_size) const78 void cache_logger::log_insert(int items_removed,
79 int item_count, int est_size) const
80 {
81 if (_impl)
82 {
83 _impl->stream << "Insert... "
84 << " dropped items: " << items_removed
85 << "; count: " << item_count
86 << "; size: " << est_size << " of " << max_size
87 << endl;
88 }
89 }
90
91 // Local Variables:
92 // mode: C++
93 // fill-column: 76
94 // c-file-style: "gnu"
95 // indent-tabs-mode: nil
96 // End:
97 // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
98