static atomic64_t buffer_history_alloc_num;
const bool buffer_track_alloc = get_env_bool("CEPH_BUFFER_TRACK");
- void buffer::inc_total_alloc(unsigned len) {
+ namespace {
+ void inc_total_alloc(unsigned len) {
if (buffer_track_alloc)
buffer_total_alloc.add(len);
}
- void buffer::dec_total_alloc(unsigned len) {
+
+ void dec_total_alloc(unsigned len) {
if (buffer_track_alloc)
buffer_total_alloc.sub(len);
}
- void buffer::inc_history_alloc(uint64_t len) {
+
+ void inc_history_alloc(uint64_t len) {
if (buffer_track_alloc) {
buffer_history_alloc_bytes.add(len);
buffer_history_alloc_num.inc();
}
}
+ }
+
+
int buffer::get_total_alloc() {
return buffer_total_alloc.read();
}
out.flags(original_flags);
}
-std::ostream& operator<<(std::ostream& out, const buffer::raw &r) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::raw &r) {
return out << "buffer::raw(" << (void*)r.data << " len " << r.len << " nref " << r.nref.read() << ")";
}
-std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::ptr& bp) {
if (bp.have_raw())
out << "buffer::ptr(" << bp.offset() << "~" << bp.length()
<< " " << (void*)bp.c_str()
return out;
}
-std::ostream& operator<<(std::ostream& out, const buffer::list& bl) {
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::list& bl) {
out << "buffer::list(len=" << bl.length() << "," << std::endl;
std::list<buffer::ptr>::const_iterator it = bl.buffers().begin();
return out;
}
-std::ostream& operator<<(std::ostream& out, const buffer::error& e)
+std::ostream& buffer::operator<<(std::ostream& out, const buffer::error& e)
{
return out << e.what();
}
-
}
#include "page.h"
#include "crc32c.h"
+#include "include/buffer_fwd.h"
#ifdef __CEPH__
# include "include/assert.h"
const static int CEPH_BUFFER_APPEND_SIZE(4096);
-class CEPH_BUFFER_API buffer {
+namespace buffer CEPH_BUFFER_API {
/*
* exceptions
*/
-public:
struct error : public std::exception{
const char *what() const throw ();
};
/// total bytes allocated
- static int get_total_alloc();
+ int get_total_alloc();
/// history total bytes allocated
- static uint64_t get_history_alloc_bytes();
+ uint64_t get_history_alloc_bytes();
/// total num allocated
- static uint64_t get_history_alloc_num();
+ uint64_t get_history_alloc_num();
/// enable/disable alloc tracking
- static void track_alloc(bool b);
+ void track_alloc(bool b);
/// count of cached crc hits (matching input)
- static int get_cached_crc();
+ int get_cached_crc();
/// count of cached crc hits (mismatching input, required adjustment)
- static int get_cached_crc_adjusted();
+ int get_cached_crc_adjusted();
/// enable/disable tracking of cached crcs
- static void track_cached_crc(bool b);
+ void track_cached_crc(bool b);
/// count of calls to buffer::ptr::c_str()
- static int get_c_str_accesses();
+ int get_c_str_accesses();
/// enable/disable tracking of buffer::ptr::c_str() calls
- static void track_c_str(bool b);
-
-private:
-
- /* hack for memory utilization debugging. */
- static void inc_total_alloc(unsigned len);
- static void inc_history_alloc(uint64_t len);
- static void dec_total_alloc(unsigned len);
+ void track_c_str(bool b);
/*
* an abstract raw buffer. with a reference count.
class raw_pipe;
class raw_unshareable; // diagnostic, unshareable char buffer
- friend std::ostream& operator<<(std::ostream& out, const raw &r);
-public:
class xio_mempool;
class xio_msg_buffer;
/*
* named constructors
*/
- static raw* copy(const char *c, unsigned len);
- static raw* create(unsigned len);
- static raw* claim_char(unsigned len, char *buf);
- static raw* create_malloc(unsigned len);
- static raw* claim_malloc(unsigned len, char *buf);
- static raw* create_static(unsigned len, char *buf);
- static raw* create_aligned(unsigned len, unsigned align);
- static raw* create_page_aligned(unsigned len);
- static raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
- static raw* create_unshareable(unsigned len);
+ raw* copy(const char *c, unsigned len);
+ raw* create(unsigned len);
+ raw* claim_char(unsigned len, char *buf);
+ raw* create_malloc(unsigned len);
+ raw* claim_malloc(unsigned len, char *buf);
+ raw* create_static(unsigned len, char *buf);
+ raw* create_aligned(unsigned len, unsigned align);
+ raw* create_page_aligned(unsigned len);
+ raw* create_zero_copy(unsigned len, int fd, int64_t *offset);
+ raw* create_unshareable(unsigned len);
#if defined(HAVE_XIO)
static raw* create_msg(unsigned len, char *buf, XioDispatchHook *m_hook);
};
- friend std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp);
/*
* list - the useful bit!
return crc;
}
};
-};
-
-#if defined(HAVE_XIO)
-xio_reg_mem* get_xio_mp(const buffer::ptr& bp);
-#endif
-
-typedef buffer::ptr bufferptr;
-typedef buffer::list bufferlist;
-typedef buffer::hash bufferhash;
-
inline bool operator>(bufferlist& l, bufferlist& r) {
for (unsigned p = 0; ; p++) {
std::ostream& operator<<(std::ostream& out, const buffer::ptr& bp);
+std::ostream& operator<<(std::ostream& out, const raw &r);
std::ostream& operator<<(std::ostream& out, const buffer::list& bl);
}
}
+#if defined(HAVE_XIO)
+xio_reg_mem* get_xio_mp(const buffer::ptr& bp);
+#endif
+
+}
+
#endif