]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/db/malloc_stats.cc
build: use dgit for download target
[ceph.git] / ceph / src / rocksdb / db / malloc_stats.cc
CommitLineData
11fdf7f2
TL
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
5//
6// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
10#include "db/malloc_stats.h"
11
12#ifndef ROCKSDB_LITE
13#include <memory>
14#include <string.h>
15
16namespace rocksdb {
17
18#ifdef ROCKSDB_JEMALLOC
19#ifdef __FreeBSD__
20#include <malloc_np.h>
21#else
22#include "jemalloc/jemalloc.h"
23#ifdef JEMALLOC_NO_RENAME
24#define malloc_stats_print je_malloc_stats_print
25#endif
26#endif
27
28typedef struct {
29 char* cur;
30 char* end;
31} MallocStatus;
32
33static void GetJemallocStatus(void* mstat_arg, const char* status) {
34 MallocStatus* mstat = reinterpret_cast<MallocStatus*>(mstat_arg);
35 size_t status_len = status ? strlen(status) : 0;
36 size_t buf_size = (size_t)(mstat->end - mstat->cur);
37 if (!status_len || status_len > buf_size) {
38 return;
39 }
40
41 snprintf(mstat->cur, buf_size, "%s", status);
42 mstat->cur += status_len;
43}
44#endif // ROCKSDB_JEMALLOC
45
46#ifdef ROCKSDB_JEMALLOC
47void DumpMallocStats(std::string* stats) {
48 MallocStatus mstat;
49 const unsigned int kMallocStatusLen = 1000000;
50 std::unique_ptr<char[]> buf{new char[kMallocStatusLen + 1]};
51 mstat.cur = buf.get();
52 mstat.end = buf.get() + kMallocStatusLen;
53 malloc_stats_print(GetJemallocStatus, &mstat, "");
54 stats->append(buf.get());
55}
56#else
57void DumpMallocStats(std::string*) {}
58#endif // ROCKSDB_JEMALLOC
59}
60#endif // !ROCKSDB_LITE