Created
July 26, 2019 01:16
-
-
Save 303248153/6638a6badfcf67dca959f0a777de7b6c to your computer and use it in GitHub Desktop.
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
--- a/src/core/reactor.cc | |
+++ b/src/core/reactor.cc | |
@@ -124,6 +124,12 @@ | |
#include <typeinfo> | |
#endif | |
+namespace { | |
+ thread_local static int schedule_count = 0; | |
+ thread_local static int schedule_urgent_count = 0; | |
+ thread_local static int epoll_count = 0; | |
+} | |
+ | |
namespace seastar { | |
struct mountpoint_params { | |
@@ -4208,6 +4214,13 @@ reactor::run_some_tasks() { | |
sched_print("run_some_tasks: start"); | |
reset_preemption_monitor(); | |
+ thread_local static size_t count = 0; | |
+ thread_local static size_t count_nonempty = 0; | |
+ thread_local static size_t total_tasks_processed = 0; | |
+ thread_local static size_t total_tasks_remained = 0; | |
+ thread_local static size_t total_time_costed = 0; | |
+ thread_local static size_t max_time_costed = 0; | |
+ | |
sched_clock::time_point t_run_completed = std::chrono::steady_clock::now(); | |
STAP_PROBE(seastar, reactor_run_tasks_start); | |
_cpu_stall_detector->start_task_run(t_run_completed); | |
@@ -4219,6 +4232,7 @@ reactor::run_some_tasks() { | |
sched_print("running tq {} {}", (void*)tq, tq->_name); | |
tq->_current = true; | |
_last_vruntime = std::max(tq->_vruntime, _last_vruntime); | |
+ auto tasks_processed_before = tq->_tasks_processed; | |
run_tasks(*tq); | |
tq->_current = false; | |
t_run_completed = std::chrono::steady_clock::now(); | |
@@ -4226,11 +4240,39 @@ reactor::run_some_tasks() { | |
account_runtime(*tq, delta); | |
sched_print("run complete ({} {}); time consumed {} usec; final vruntime {} empty {}", | |
(void*)tq, tq->_name, delta / 1us, tq->_vruntime, tq->_q.empty()); | |
+ ++count; | |
+ total_tasks_processed += tq->_tasks_processed - tasks_processed_before; | |
+ total_time_costed += delta / 1ms; | |
+ max_time_costed = std::max(max_time_costed, (size_t)(delta / 1ms)); | |
if (!tq->_q.empty()) { | |
insert_active_task_queue(tq); | |
+ ++count_nonempty; | |
+ total_tasks_remained += tq->_q.size(); | |
} else { | |
tq->_active = false; | |
} | |
+ if (count % 1000 == 0) { | |
+ std::cout << "count: " << count << | |
+ ", epoll_count: " << epoll_count << | |
+ ", non_empty_rate: " << ((double)count_nonempty / 1000 * 100) << | |
+ "%, urgent_rate: " << ((double)schedule_urgent_count / (schedule_urgent_count + schedule_count) * 100) << | |
+ "%, average_tasks_processed: " << ((double)total_tasks_processed / 1000) << | |
+ ", average_tasks_remained: " << ((double)total_tasks_remained / 1000) << | |
+ ", average_time_costed: " << ((double)total_time_costed / 1000) << | |
+ ", max_time_costed: " << max_time_costed << std::endl; | |
+ epoll_count = 0; | |
+ count_nonempty = 0; | |
+ schedule_urgent_count = 0; | |
+ schedule_count = 0; | |
+ total_tasks_processed = 0; | |
+ total_tasks_remained = 0; | |
+ total_time_costed = 0; | |
+ max_time_costed = 0; | |
+ schedule(make_task([begin = std::chrono::steady_clock::now(), count=count] { | |
+ std::cout << "task from count " << count << " executed after " << | |
+ ((std::chrono::steady_clock::now() - begin) / 1ms) << "ms" << std::endl; | |
+ })); | |
+ } | |
} while (have_more_tasks() && !need_preempt()); | |
_cpu_stall_detector->end_task_run(t_run_completed); | |
STAP_PROBE(seastar, reactor_run_tasks_end); | |
@@ -4574,6 +4616,7 @@ reactor::poller::~poller() { | |
bool | |
reactor_backend_epoll::wait_and_process(int timeout, const sigset_t* active_sigmask) { | |
+ ++epoll_count; | |
std::array<epoll_event, 128> eevt; | |
int nr = ::epoll_pwait(_epollfd.get(), eevt.data(), eevt.size(), timeout, active_sigmask); | |
if (nr == -1 && errno == EINTR) { | |
@@ -4954,10 +4997,12 @@ future<size_t> readable_eventfd::wait() { | |
} | |
void schedule(std::unique_ptr<task>&& t) noexcept { | |
+ ++schedule_count; | |
engine().add_task(std::move(t)); | |
} | |
void schedule_urgent(std::unique_ptr<task>&& t) noexcept { | |
+ ++schedule_urgent_count; | |
engine().add_urgent_task(std::move(t)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment