This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
aa21707
commit a55bdca
Showing
50 changed files
with
795 additions
and
829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.