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

feat: support perfcounter and more information trace log - #945

Merged
foreverneverer merged 19 commits into
XiaoMi:masterfrom
foreverneverer:refactor-tracer
Nov 1, 2021
Merged

foreverneverer merged 19 commits into
XiaoMi:masterfrom
foreverneverer:refactor-tracer

Conversation

@foreverneverer

@foreverneverer foreverneverer commented Oct 26, 2021 •

Copy link
Copy Markdown
Contributor

apache/incubator-pegasus#883

The pr add two main feature:

  1. support the trace point can be reported to monitoring system
  2. support multi-subtracer

New-Config

+ enable_latency_tracer_report = false
+ latency_tracer_counter_name_prefix = trace_latency

+ [task.LPC_WRITE_REPLICATION_LOG_SHARED]
+   enable_trace = true # true will mark the task will be traced latency if open global trace

Log Format Example

	***************[TRACE:[primary.LPC_LATENCY_TRACE]mutation[3.4.3.4646268]]***************
	TRACE:name=replica_2pc.cpp:165:init_prepare                                      , span=                3117, total=                3117, ts=1634899499401766091 
	TRACE:name=prepare_list.cpp:78:prepare                                           , span=                2468, total=                5585, ts=1634899499401768559 
	TRACE:name=mutation_log.cpp:57:append                                            , span=               63398, total=               68983, ts=1634899499401831957 
	TRACE:name=mutation_log.cpp:133:commit_pending_mutations                         , span=                4190, total=               73173, ts=1634899499401836147 
	TRACE:name=mutation_log.cpp:143:operator()_commit_pending_completed              , span=               22229, total=               95402, ts=1634899499401858376 
	TRACE:name=replica_2pc.cpp:544:on_append_log_completed                           , span=                7926, total=              103328, ts=1634899499401866302 
	TRACE:name=replica.cpp:295:execute_mutation                                      , span=             1308213, total=             1411541, ts=1634899499403174515 
	TRACE:name=replication_app_base.cpp:477:apply_mutation                           , span=                1195, total=             1412736, ts=1634899499403175710 
	TRACE:name=replica.cpp:366:execute_mutation_completed                            , span=               74476, total=             1487212, ts=1634899499403250186 
	          [TRACE:[primary.LPC_LATENCY_TRACE]127.0.0.1:34802]          
	 TRACE:name=prepare.replica_2pc.cpp:327:send_prepare_message                      , span=                1330, total=                1330, ts=1634899499401772653 
	 TRACE:name=prepare.replica_2pc.cpp:639:on_prepare_reply_remote_rec_prepare       , span=               43233, total=               44563, ts=1634899499401815886 
	 TRACE:name=prepare.replica_2pc.cpp:640:on_prepare_reply_remote_reply_prepare     , span=               92377, total=              136940, ts=1634899499401908263 
	 TRACE:name=prepare.replica_2pc.cpp:641:on_prepare_reply                          , span=               37115, total=              174055, ts=1634899499401945378 
	          [TRACE:[primary.LPC_LATENCY_TRACE]127.0.0.1:34803]          
	 TRACE:name=prepare.replica_2pc.cpp:327:send_prepare_message                      , span=                2005, total=                2005, ts=1634899499401806364 
	 TRACE:name=prepare.replica_2pc.cpp:639:on_prepare_reply_remote_rec_prepare       , span=             1269964, total=             1271969, ts=1634899499403076328 
	 TRACE:name=prepare.replica_2pc.cpp:640:on_prepare_reply_remote_reply_prepare     , span=               46020, total=             1317989, ts=1634899499403122348 
	 TRACE:name=prepare.replica_2pc.cpp:641:on_prepare_reply                          , span=               50075, total=             1368064, ts=1634899499403172423 
	          [TRACE:[primary.LPC_WRITE_REPLICATION_LOG_SHARED]aio_task]          
	 TRACE:name=commit.native_linux_aio_provider.cpp:137:submit_aio_task              , span=                3904, total=                3904, ts=1634899499401841919 
	 TRACE:name=commit.native_linux_aio_provider.cpp:144:aio_internal                 , span=                7127, total=               11031, ts=1634899499401849046 
	 TRACE:name=commit.native_linux_aio_provider.cpp:158:aio_internal_completed       , span=                5721, total=               16752, ts=1634899499401854767 

@foreverneverer
foreverneverer marked this pull request as draft October 26, 2021 04:21
@foreverneverer
foreverneverer marked this pull request as ready for review October 26, 2021 08:59
@foreverneverer foreverneverer added the type/config-change PR that made modification on configs, which should be noted in release note. label Oct 26, 2021
Comment thread include/dsn/utils/latency_tracer.h Resolved
Comment thread include/dsn/utils/latency_tracer.h Resolved
Comment thread include/dsn/utils/latency_tracer.h Resolved
Comment thread src/utils/latency_tracer.cpp Resolved
Comment thread src/utils/latency_tracer.cpp Resolved
Comment thread src/utils/test/latency_tracer_test.cpp Resolved
@hycdong

hycdong commented Oct 27, 2021

Copy link
Copy Markdown
Contributor

I think this pull request adds a new feature, it is more suitable to use feat rather than refactor in title.
Besides, I suggest adding more in pull request description about how to configure a sub-tracer.

@foreverneverer foreverneverer changed the title refactor: support perfcounter and more information trace log feat: support perfcounter and more information trace log Oct 27, 2021
@foreverneverer

foreverneverer commented Oct 27, 2021 •

Copy link
Copy Markdown
Contributor Author

I think this pull request adds a new feature, it is more suitable to use feat rather than refactor in title. Besides, I suggest adding more in pull request description about how to configure a sub-tracer.

sub_tracer is old concept of origin pr and the code has some explain comment, it shoudn't explain again in this pr again. And I update some comment about it

Comment thread include/dsn/utils/latency_tracer.h Outdated
#include <dsn/utility/synchronize.h>
#include <dsn/utility/flags.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/perf_counter/perf_counters.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

Comment thread include/dsn/utils/latency_tracer.h Outdated

std::string name() { return _name; }

std::string description() { return _description; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string& description() const

Comment thread include/dsn/utils/latency_tracer.h Outdated

dsn::task_code _task_code;

utils::rw_lock_nr _point_lock;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   utils::rw_lock_nr _point_lock; // {
    std::map<int64_t, std::string> _points;
// }

Comment thread include/dsn/utils/latency_tracer.h Outdated
std::shared_ptr<latency_tracer> _sub_tracer;

std::string _parent_point_name;
utils::rw_lock_nr _sub_lock;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

uint64_t ts = dsn_now_ns();
utils::auto_write_lock write(_lock);
_points[ts] = stage_name;
utils::auto_write_lock write(_point_lock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
    utils::auto_write_lock write(_point_lock);
    _points.emplace(ts, stage_name);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_last_time need also lock

Comment thread src/utils/latency_tracer.cpp Outdated

traces.append(fmt::format("\t***************[TRACE:{}]***************\n", _name));
uint64_t previous_time = _start_time;
utils::auto_read_lock point_lock(_point_lock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these two locks produce dead lock?

@foreverneverer foreverneverer Oct 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I will fix

Comment thread src/utils/latency_tracer.cpp Outdated
if (time_used < _threshold) {
void latency_tracer::dump_trace_points(/*out*/ std::string &traces)
{
if (!FLAGS_enable_latency_tracer || !_enable_trace || _threshold < 0 || _points.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code have thread safet issues?

_points.empty()

@foreverneverer foreverneverer Oct 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seem to be not, has updated

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

type/config-change PR that made modification on configs, which should be noted in release note.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants