diff --git a/static_core/runtime/options.yaml b/static_core/runtime/options.yaml index 4e94c55c52eca436c13224843c1021a6df6b8f13..e288b11cb4eb64c203c7f7bda7517c41b51a9e0e 100644 --- a/static_core/runtime/options.yaml +++ b/static_core/runtime/options.yaml @@ -125,7 +125,7 @@ options: - name: sampling-profiler-create type: bool - default: false + default: true description: Is the sampling profiler created and available during runtime execution - name: sampling-profiler-startup-run diff --git a/static_core/runtime/tooling/sampler/sampling_profiler.cpp b/static_core/runtime/tooling/sampler/sampling_profiler.cpp index 6631159edc56c264764718f97b243fddb889ccb4..b58f366cfc197faaaab1462fcffc20681b8ac2ab 100644 --- a/static_core/runtime/tooling/sampler/sampling_profiler.cpp +++ b/static_core/runtime/tooling/sampler/sampling_profiler.cpp @@ -112,11 +112,11 @@ Sampler *Sampler::Create() static void LogProfilerStats() { - LOG(INFO, PROFILER) << "Total samples: " << g_sTotalSamples; - LOG(INFO, PROFILER) << "Lost samples: " << g_sLostSamples; - LOG(INFO, PROFILER) << "Lost samples(Invalid method ptr): " << g_sLostInvalidSamples; - LOG(INFO, PROFILER) << "Lost samples(Invalid pf ptr): " << g_sLostNotFindSamples; - LOG(INFO, PROFILER) << "Lost samples(SIGSEGV occured): " << g_sLostSegvSamples; + LOG(WARNING, PROFILER) << "Sampler internal: Total samples: " << g_sTotalSamples; + LOG(WARNING, PROFILER) << "Sampler internal: Lost samples: " << g_sLostSamples; + LOG(WARNING, PROFILER) << "Sampler internal: Lost samples(Invalid method ptr): " << g_sLostInvalidSamples; + LOG(WARNING, PROFILER) << "Sampler internal: Lost samples(Invalid pf ptr): " << g_sLostNotFindSamples; + LOG(WARNING, PROFILER) << "Sampler internal: Lost samples(SIGSEGV occured): " << g_sLostSegvSamples; } /* static */ @@ -195,12 +195,12 @@ bool Sampler::Start(std::unique_ptr &&writer) { // Atomic with acquire order reason: To ensure start/stop load correctly if (isActive_.load(std::memory_order_acquire)) { - LOG(ERROR, PROFILER) << "Attemp to start sampling profiler while it's already started"; + LOG(ERROR, PROFILER) << "Sampler internal: Attemp to start sampling profiler while it's already started"; return false; } if (UNLIKELY(!communicator_.Init())) { - LOG(ERROR, PROFILER) << "Failed to create pipes for sampling listener. Profiler cannot be started"; + LOG(ERROR, PROFILER) << "Sampler internal: Failed to create pipes for sampling listener. Profiler cannot be started"; return false; } @@ -213,7 +213,7 @@ bool Sampler::Start(std::unique_ptr &&writer) // All prepairing actions should be done before this thread is started samplerThread_ = std::make_unique(&Sampler::SamplerThreadEntry, this); samplerTid_ = samplerThread_->native_handle(); - LOG(INFO, PROFILER) << "Sampling profiler started"; + LOG(WARNING, PROFILER) << "Sampler internal: Sampling profiler started"; return true; } @@ -221,15 +221,15 @@ bool Sampler::Stop() { // Atomic with acquire order reason: To ensure start/stop load correctly if (!isActive_.load(std::memory_order_acquire)) { - LOG(ERROR, PROFILER) << "Attemp to stop sampling profiler, but it was not started"; + LOG(ERROR, PROFILER) << "Sampler internal: Attemp to stop sampling profiler, but it was not started"; return false; } if (!samplerThread_->joinable()) { - LOG(FATAL, PROFILER) << "Sampling profiler thread unexpectedly disappeared"; + LOG(FATAL, PROFILER) << "Sampler internal: Sampling profiler thread unexpectedly disappeared"; UNREACHABLE(); } if (!listenerThread_->joinable()) { - LOG(FATAL, PROFILER) << "Listener profiler thread unexpectedly disappeared"; + LOG(FATAL, PROFILER) << "Sampler internal: Listener profiler thread unexpectedly disappeared"; UNREACHABLE(); } @@ -244,7 +244,7 @@ bool Sampler::Stop() samplerTid_ = 0; listenerTid_ = 0; - LOG(INFO, PROFILER) << "Sampling profiler stopped"; + LOG(WARNING, PROFILER) << "Sampler internal: Sampling profiler stopped"; LogProfilerStats(); return true; } @@ -268,7 +268,7 @@ void Sampler::CollectThreads() auto tManager = runtime_->GetPandaVM()->GetThreadManager(); if (UNLIKELY(tManager == nullptr)) { // NOTE(m.strizhak): make it for languages without thread_manager - LOG(FATAL, PROFILER) << "Thread manager is nullptr"; + LOG(FATAL, PROFILER) << "Sampler internal: Thread manager is nullptr"; UNREACHABLE(); } @@ -447,12 +447,14 @@ void SigProfSamplingProfilerHandler([[maybe_unused]] int signum, [[maybe_unused] if (g_sCurrentHandlersCounter == 0) { // Sampling ended if S_CURRENT_HANDLERS_COUNTER is 0. Thread started executing handler for signal // that was sent before end, so thread is late now and we should return from handler + LOG(WARNING, PROFILER) << "Sampler internal: g_sCurrentHandlersCounter == 0"; return; } auto scopedHandlersCounting = ScopedHandlersCounting(); Coroutine *coro = Coroutine::GetCurrent(); if (coro != nullptr && coro->GetCoroutineStatus() != Coroutine::Status::RUNNING) { + LOG(WARNING, PROFILER) << "coro != nullptr && coro->GetCoroutineStatus() != Coroutine::Status::RUNNING"; return; } @@ -462,6 +464,7 @@ void SigProfSamplingProfilerHandler([[maybe_unused]] int signum, [[maybe_unused] // Checking that code is being executed auto *framePtr = reinterpret_cast(mthread->GetCurrentFrame()); if (framePtr == nullptr) { + LOG(WARNING, PROFILER) << "framePtr == nullptr"; return; } @@ -527,14 +530,14 @@ void Sampler::SamplerThreadEntry() struct sigaction oldAction {}; if (sigaction(SIGPROF, &action, &oldAction) == -1) { - LOG(FATAL, PROFILER) << "Sigaction failed, can't start profiling"; + LOG(FATAL, PROFILER) << "Sampler internal: Sigaction failed, can't start profiling"; UNREACHABLE(); } // We keep handler assigned to SigProfSamplingProfilerHandler after sampling end because // otherwice deadlock can happen if signal will be slow and reach thread after handler resignation if (oldAction.sa_sigaction != nullptr && oldAction.sa_sigaction != SigProfSamplingProfilerHandler) { - LOG(FATAL, PROFILER) << "SIGPROF signal handler was overriden in sampling profiler"; + LOG(FATAL, PROFILER) << "Sampler internal: SIGPROF signal handler was overriden in sampling profiler"; UNREACHABLE(); } ++g_sCurrentHandlersCounter; @@ -547,7 +550,7 @@ void Sampler::SamplerThreadEntry() for (const auto &threadId : managedThreads_) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) if (syscall(SYS_tgkill, pid, threadId, SIGPROF) != 0) { - LOG(DEBUG, PROFILER) << "Can't send signal to thread"; + LOG(WARNING, PROFILER) << "Sampler internal: Can't send signal to thread"; } } } diff --git a/static_core/runtime/tooling/tools.cpp b/static_core/runtime/tooling/tools.cpp index 07b87e77e5108b0edb8f21c07e659d17ecee550f..732e17a5fe7577ca6fad21796a2f1e9fa0a86c23 100644 --- a/static_core/runtime/tooling/tools.cpp +++ b/static_core/runtime/tooling/tools.cpp @@ -22,7 +22,7 @@ extern "C" PANDA_PUBLIC_API int StartSamplingProfiler(const char *asptFilename, { auto *runtime = Runtime::GetCurrent(); if (runtime == nullptr) { - LOG(DEBUG, PROFILER) << "That runtime is not created."; + LOG(WARNING, PROFILER) << "Sampler internal: That runtime is not created."; return 1; } return static_cast( @@ -33,7 +33,7 @@ extern "C" PANDA_PUBLIC_API void StopSamplingProfiler() { auto *runtime = Runtime::GetCurrent(); if (runtime == nullptr) { - LOG(DEBUG, PROFILER) << "That runtime is not created."; + LOG(WARNING, PROFILER) << "Sampler internal: That runtime is not created."; return; } runtime->GetTools().StopSamplingProfiler();