Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(new_metrics): merge prometheus-dev into master branch #1126

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b5dea30
feat: implement long adder to optimize the counter of new metrics sys…
empiredan Jan 28, 2022
7fc37c8
feat(new_metrics): implement the metric entity & its prototype (#1070)
empiredan Mar 10, 2022
d592fb3
feat(new_metrics): implement the metric registry (#1073)
empiredan Mar 12, 2022
0d632e3
feat(new_metrics): implement the metric & its prototype (#1075)
empiredan Mar 18, 2022
03d0ec0
feat(new_metrics): implement the gauge (#1079)
empiredan Mar 23, 2022
863325b
feat(new_metrics): implement the counter (#1081)
empiredan Mar 25, 2022
2a7a21a
feat(new_metrics): implement the volatile counter (#1083)
empiredan Apr 13, 2022
bf33b2b
feat(new_metrics): make the counter increment monotonically (#1095)
empiredan Apr 19, 2022
b50653e
feat(new_metrics): support to find multiple nth elements of a sequenc…
empiredan May 25, 2022
ce34b7d
feat(new_metrics): implement the percentile (#1112)
empiredan Jun 17, 2022
42492b1
feat: implement long adder to optimize the counter of new metrics sys…
empiredan Jan 28, 2022
1e3789b
feat(new_metrics): implement the metric entity & its prototype (#1070)
empiredan Mar 10, 2022
fe1f009
feat(new_metrics): implement the metric registry (#1073)
empiredan Mar 12, 2022
028512b
feat(new_metrics): implement the metric & its prototype (#1075)
empiredan Mar 18, 2022
e7c4a6a
feat(new_metrics): implement the gauge (#1079)
empiredan Mar 23, 2022
4c7b929
feat(new_metrics): implement the counter (#1081)
empiredan Mar 25, 2022
b3dc8d2
feat(new_metrics): implement the volatile counter (#1083)
empiredan Apr 13, 2022
447bde7
feat(new_metrics): make the counter increment monotonically (#1095)
empiredan Apr 19, 2022
9cecf7f
feat(new_metrics): support to find multiple nth elements of a sequenc…
empiredan May 25, 2022
030bfa0
feat(new_metrics): implement the percentile (#1112)
empiredan Jun 17, 2022
c432a82
Merge branch 'prometheus-dev' of github.com:XiaoMi/rdsn into promethe…
Jun 20, 2022
5d6dccc
feat(new_metrics): put added files into file list of apache license
empiredan Jun 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ header:
- 'include/dsn/utility/rand.h'
- 'include/dsn/utility/math.h'
- 'include/dsn/utility/defer.h'
- 'include/dsn/utility/alloc.h'
- 'include/dsn/utility/casts.h'
- 'include/dsn/utility/long_adder.h'
- 'include/dsn/utility/metrics.h'
- 'include/dsn/utility/nth_element.h'
- 'src/aio/aio_task.cpp'
- 'src/aio/test/main.cpp'
- 'src/meta/test/meta_http_service_test.cpp'
Expand Down Expand Up @@ -209,6 +214,17 @@ header:
- 'src/utils/rand.cpp'
- 'src/utils/throttling_controller.cpp'
- 'src/utils/output_utils.cpp'
- 'src/utils/alloc.cpp'
- 'src/utils/long_adder.cpp'
- 'src/utils/long_adder_bench/long_adder_bench.cpp'
- 'src/utils/metrics.cpp'
- 'src/utils/shared_io_service.cpp'
- 'src/utils/test/long_adder_test.cpp'
- 'src/utils/test/metrics_test.cpp'
- 'src/utils/test/nth_element_bench/nth_element_bench.cpp'
- 'src/utils/test/nth_element_test.cpp'
- 'src/utils/test/nth_element_utils.h'
- 'src/utils/test/percentile_utils.h'
- 'src/common/partition_split.thrift'
- 'src/common/common.cpp'
- 'src/common/consensus.thrift'
Expand Down
84 changes: 84 additions & 0 deletions include/dsn/utility/alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <algorithm>
#include <functional>
#include <memory>
#include <new>

#include <dsn/c/api_utilities.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/ports.h>

namespace dsn {

#ifdef CACHELINE_SIZE

extern void *cacheline_aligned_alloc(size_t size);

extern void cacheline_aligned_free(void *mem_block);

template <typename T>
using cacheline_aligned_ptr = typename std::unique_ptr<T, std::function<void(void *)>>;

template <typename T>
cacheline_aligned_ptr<T> cacheline_aligned_alloc_array(size_t len)
{
void *buffer = cacheline_aligned_alloc(sizeof(T) * len);
if (dsn_unlikely(buffer == nullptr)) {
return cacheline_aligned_ptr<T>(nullptr, [](void *) {});
}

T *array = new (buffer) T[len];

#ifndef NDEBUG
if (sizeof(T) <= CACHELINE_SIZE && (sizeof(T) & (sizeof(T) - 1)) == 0) {
for (size_t i = 0; i < len; ++i) {
T *elem = &(array[i]);
dassert_f((reinterpret_cast<const uintptr_t>(elem) & (sizeof(T) - 1)) == 0,
"unaligned array element for cache line: array={}, length={}, index={}, "
"elem={}, elem_size={}, mask={}, cacheline_size={}",
fmt::ptr(array),
len,
i,
fmt::ptr(elem),
sizeof(T),
sizeof(T) - 1,
CACHELINE_SIZE);
}
}
#endif

return cacheline_aligned_ptr<T>(array, cacheline_aligned_free);
}

template <typename T>
cacheline_aligned_ptr<T> cacheline_aligned_alloc_array(size_t len, const T &val)
{
auto array = cacheline_aligned_alloc_array<T>(len);
if (array) {
std::fill(array.get(), array.get() + len, val);
}

return array;
}

#endif

} // namespace dsn
47 changes: 47 additions & 0 deletions include/dsn/utility/casts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <cassert>
#include <type_traits>

namespace dsn {

// Downcasting is to convert a base-class pointer(reference) to a derived-class
// pointer(reference). As a usual approach, RTTI (dynamic_cast<>) is not efficient.
// Instead, we can perform a compile-time assertion check whether one is derived
// from another; then, just use static_cast<> to do the conversion faster. RTTI is
// also run in debug mode to do double-check.

template <typename To, typename From>
inline To down_cast(From *from)
{
// Perform a compile-time assertion to check whether <From> class is derived from <To> class.
static_assert(std::is_base_of<typename std::remove_pointer<From>::type,
typename std::remove_pointer<To>::type>::value,
"<From> class is not derived from <To> class");

// Use RTTI to do double-check, though in practice the unit tests are seldom built in debug
// mode. For example, the unit tests of github CI for both rDSN and Pegasus are built in
// release mode.
assert(from == NULL || dynamic_cast<To>(from) != NULL);

return static_cast<To>(from);
}

} // namespace dsn
Loading