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

Commit

Permalink
remove c api for perf_counter
Browse files Browse the repository at this point in the history
Summary: Ref T10562

Test Plan: N/A

Reviewers: qinzuoyan, cailiuyang, wutao1, heyuchen, laiyingchun

Reviewed By: qinzuoyan

Subscribers: #pegasus

Maniphest Tasks: T10562

Differential Revision: https://phabricator.d.xiaomi.net/D81734
  • Loading branch information
shengofsun committed Feb 2, 2018
1 parent aa21707 commit a55bdca
Show file tree
Hide file tree
Showing 50 changed files with 795 additions and 829 deletions.
46 changes: 0 additions & 46 deletions include/dsn/c/api_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,52 +368,6 @@ extern DSN_API uint64_t dsn_crc64_concatenate(uint32_t xy_init,
size_t y_size);
/*@}*/

/*!
@defgroup perf-counter Performance Counters
@ingroup service-api-utilities
Performance Counters
Note developers can plug into rDSN their own performance counter
implementation, so as to integrate rDSN performance counters into
their own cluster operation systems.
@{
*/
typedef enum dsn_perf_counter_type_t {
COUNTER_TYPE_NUMBER,
COUNTER_TYPE_VOLATILE_NUMBER, // special kind of NUMBER which will be reset on get
COUNTER_TYPE_RATE,
COUNTER_TYPE_NUMBER_PERCENTILES,
COUNTER_TYPE_INVALID,
COUNTER_TYPE_COUNT
} dsn_perf_counter_type_t;

typedef enum dsn_perf_counter_percentile_type_t {
COUNTER_PERCENTILE_50,
COUNTER_PERCENTILE_90,
COUNTER_PERCENTILE_95,
COUNTER_PERCENTILE_99,
COUNTER_PERCENTILE_999,

COUNTER_PERCENTILE_COUNT,
COUNTER_PERCENTILE_INVALID
} dsn_perf_counter_percentile_type_t;

extern DSN_API dsn_handle_t dsn_perf_counter_create(const char *section,
const char *name,
dsn_perf_counter_type_t type,
const char *description);
extern DSN_API void dsn_perf_counter_remove(dsn_handle_t handle);
extern DSN_API void dsn_perf_counter_increment(dsn_handle_t handle);
extern DSN_API void dsn_perf_counter_decrement(dsn_handle_t handle);
extern DSN_API void dsn_perf_counter_add(dsn_handle_t handle, uint64_t val);
extern DSN_API void dsn_perf_counter_set(dsn_handle_t handle, uint64_t val);
extern DSN_API double dsn_perf_counter_get_value(dsn_handle_t handle);
extern DSN_API uint64_t dsn_perf_counter_get_integer_value(dsn_handle_t handle);
extern DSN_API double dsn_perf_counter_get_percentile(dsn_handle_t handle,
dsn_perf_counter_percentile_type_t type);
/*@}*/

/*!
@defgroup memory Memory Management
@ingroup service-api-utilities
Expand Down
86 changes: 0 additions & 86 deletions include/dsn/cpp/perf_counter_.h

This file was deleted.

114 changes: 114 additions & 0 deletions include/dsn/cpp/perf_counter_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Microsoft Corporation
*
* -=- Robust Distributed System Nucleus (rDSN) -=-
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#include <dsn/service_api_c.h>
#include <dsn/tool-api/perf_counter.h>
#include <dsn/tool-api/perf_counters.h>

namespace dsn {

//
// perf_counter_wrapper is a wrapper class for perf-counter operations, users should use this class
// instead of the dsn::perf_counter where a performance counter is needed.
//
// for example:
// class A{
// public:
// A() {
// _p1.init_global_counter(...)
// _p2.init_app_counter(...)
// }
// private:
// perf_counter_wrapper _p1;
// perf_counter_wrapper _p2;
// };
//
// user should call init_global_counter/init_app_counter to initialize the counter.
// all the initialized counters are stored in the singleton dsn::perf_counters,
// users can collect all counters of the process and intergrate it with monitor system.
//
// after the init_xxx_counter is called, the counter constructed with the (app, section, name) is
// OWNED by object of type A.
// if user declare another perf_counter_wrapper variable and initialized with same
// (app, section, name) will get nullptr of _counter.
//
class perf_counter_wrapper
{
public:
perf_counter_wrapper() { _counter = nullptr; }

perf_counter_wrapper(const perf_counter_wrapper &other) = delete;
perf_counter_wrapper(perf_counter_wrapper &other) = delete;
perf_counter_wrapper(perf_counter_wrapper &&other) = delete;
perf_counter_wrapper &operator=(const perf_counter_wrapper &other) = delete;
perf_counter_wrapper &operator=(perf_counter_wrapper &other) = delete;
perf_counter_wrapper &operator=(perf_counter_wrapper &&other) = delete;

~perf_counter_wrapper() { clear(); }

// clear the real perf-counter object.
// call this function if you want free the counter before the wrapper's destructor is called
void clear()
{
if (nullptr != _counter) {
dsn::perf_counters::instance().remove_counter(_counter->full_name());
_counter = nullptr;
}
}

// init app counter create counters for some specific service_app, so different
// service_app can create counter with the same name.
void init_app_counter(const char *section,
const char *name,
dsn_perf_counter_type_t type,
const char *dsptr)
{
dsn::perf_counter_ptr c =
dsn::perf_counters::instance().new_app_counter(section, name, type, dsptr);
_counter = c.get();
}

// init global counter create counters globally.
void init_global_counter(const char *app,
const char *section,
const char *name,
dsn_perf_counter_type_t type,
const char *dsptr)
{
dsn::perf_counter_ptr c =
dsn::perf_counters::instance().new_global_counter(app, section, name, type, dsptr);
_counter = c.get();
}

dsn::perf_counter *get() const { return _counter; }
dsn::perf_counter *operator->() const { return _counter; }
private:
// use raw pointer to make the class object small, so it can be accessed quickly
dsn::perf_counter *_counter;
};
}
4 changes: 2 additions & 2 deletions include/dsn/dist/failure_detector/failure_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

#include <dsn/dist/failure_detector/fd.client.h>
#include <dsn/dist/failure_detector/fd.server.h>
#include <dsn/cpp/perf_counter_.h>
#include <dsn/cpp/perf_counter_wrapper.h>

namespace dsn {
namespace fd {
Expand Down Expand Up @@ -212,7 +212,7 @@ class failure_detector : public failure_detector_service,
bool _use_allow_list;
allow_list _allow_list;

perf_counter_ _recent_beacon_fail_count;
perf_counter_wrapper _recent_beacon_fail_count;

protected:
mutable service::zlock _lock;
Expand Down
1 change: 1 addition & 0 deletions include/dsn/dist/replication/meta_service_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <dsn/cpp/service_app.h>

extern "C" dsn_error_t dsn_meta_server_bridge(int argc, char **argv);
extern "C" void dsn_meta_sever_register_providers();

namespace dsn {
namespace replication {
Expand Down
1 change: 0 additions & 1 deletion include/dsn/dist/replication/replication_app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <dsn/dist/replication/replication.types.h>
#include <dsn/dist/replication/replication_other_types.h>
#include <dsn/dist/replication/replication.codes.h>
#include <dsn/cpp/perf_counter_.h>
#include <atomic>

namespace dsn {
Expand Down
30 changes: 20 additions & 10 deletions include/dsn/tool-api/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@
#include <sstream>
#include <vector>

typedef enum dsn_perf_counter_type_t {
COUNTER_TYPE_NUMBER,
COUNTER_TYPE_VOLATILE_NUMBER, // special kind of NUMBER which will be reset on get
COUNTER_TYPE_RATE,
COUNTER_TYPE_NUMBER_PERCENTILES,
COUNTER_TYPE_INVALID,
COUNTER_TYPE_COUNT
} dsn_perf_counter_type_t;

typedef enum dsn_perf_counter_percentile_type_t {
COUNTER_PERCENTILE_50,
COUNTER_PERCENTILE_90,
COUNTER_PERCENTILE_95,
COUNTER_PERCENTILE_99,
COUNTER_PERCENTILE_999,

COUNTER_PERCENTILE_COUNT,
COUNTER_PERCENTILE_INVALID
} dsn_perf_counter_percentile_type_t;

namespace dsn {

/*!
Expand Down Expand Up @@ -83,16 +103,6 @@ class perf_counter : public ref_counter
typedef perf_counter *(*factory)(
const char *, const char *, const char *, dsn_perf_counter_type_t, const char *);

public:
DSN_API static perf_counter_ptr get_counter(const char *app,
const char *section,
const char *name,
dsn_perf_counter_type_t flags,
const char *dsptr,
bool create_if_not_exist = false);

DSN_API static bool remove_counter(const char *full_name);

public:
perf_counter(const char *app,
const char *section,
Expand Down
Loading

0 comments on commit a55bdca

Please sign in to comment.