add codes for profiling

This commit is contained in:
falsycat 2022-11-20 16:29:10 +09:00
parent d7fe51d946
commit 93312c6d04
4 changed files with 43 additions and 14 deletions

View File

@ -9,6 +9,8 @@
#include <yas/serialize.hpp>
#include <yas/types/std/map.hpp>
#include <tracy/Tracy.hpp>
#include "nf7.hh"
#include "common/dir.hh"
@ -122,6 +124,9 @@ class GenericDir : public nf7::FileBase::Feature, public nf7::Dir {
}
void UpdateChildren(bool early) noexcept {
for (auto& p : items_) {
ZoneScopedN("update child");
ZoneText(p.first.data(), p.first.size());
auto& f = *p.second;
auto* ditem = f.interface<nf7::DirItem>();

View File

@ -16,6 +16,8 @@
#include <ImNodes.h>
#include <tracy/Tracy.hpp>
#include <yaml-cpp/yaml.h>
#include <yas/serialize.hpp>
@ -306,6 +308,9 @@ class Network::Item final {
void Detach() noexcept;
void Update() noexcept {
ZoneScoped;
ZoneValue(id_);
assert(owner_);
ImGui::PushID(file_.get());
file_->Update();
@ -386,6 +391,8 @@ class Network::Lambda : public Node::Lambda,
// send input from outer to input handlers
if (in.sender == parent) {
ZoneScopedN("return value");
for (auto& item : f_->items_) {
if (item->iflags() & InternalNode::kInputHandler) {
try {
@ -401,6 +408,8 @@ class Network::Lambda : public Node::Lambda,
// send an output from children as input to children
try {
ZoneScopedN("transmit value");
auto itr = idmap_.find(in.sender.get());
if (itr == idmap_.end()) {
throw nf7::Exception {"called by unknown lambda"};

View File

@ -12,6 +12,8 @@
#include <yas/types/std/unordered_set.hpp>
#include <yas/types/std/string.hpp>
#include <tracy/Tracy.hpp>
#include "nf7.hh"
#include "common/config.hh"

41
main.cc
View File

@ -126,6 +126,7 @@ void WorkerThread() noexcept {
FrameMarkEnd(kThreadId);
}
TracyMessageL("SyncWorker exitting");
}
void AsyncThread() noexcept {
@ -160,10 +161,11 @@ void AsyncThread() noexcept {
FrameMarkEnd(kThreadId);
}
TracyMessageL("AsyncWorker exitting");
}
void GLThread(GLFWwindow* window) noexcept {
[[maybe_unused]] const char kThreadId[] = "AsyncWorker";
[[maybe_unused]] const char kThreadId[] = "GLWorker";
tracy::SetThreadName("GLWorker");
std::unique_lock<std::mutex> k {cycle_mtx_};
@ -210,6 +212,7 @@ void GLThread(GLFWwindow* window) noexcept {
FrameMarkEnd(kThreadId);
}
TracyMessageL("GLWorker exitting");
}
@ -487,16 +490,15 @@ int main(int, char**) {
// load GUI font
if (std::filesystem::exists(kFontPath)) {
ZoneScopedN("load GUI font");
io.Fonts->AddFontFromFileTTF(
kFontPath, 16.f, nullptr, io.Fonts->GetGlyphRangesJapanese());
}
// main loop
[[maybe_unused]] const char kThreadId[] = "GUI";
::Env env;
glfwShowWindow(window);
while (!glfwWindowShouldClose(window) && !env.exitRequested()) {
FrameMarkStart(kThreadId);
nf7::Stopwatch sw;
{
@ -553,7 +555,7 @@ int main(int, char**) {
}
std::this_thread::sleep_for(kFrameDur - sw.dur());
FrameMarkEnd(kThreadId);
FrameMark;
}
// sync with worker thread and tear down filesystem
@ -563,8 +565,12 @@ int main(int, char**) {
cycle_cv_.notify_all();
cycle_cv_.wait(k, []() { return cycle_ == kUpdate; });
}
assert(cycle_ == kUpdate);
env.TearDownRoot();
{
ZoneScopedN("teardown root");
assert(cycle_ == kUpdate);
env.TearDownRoot();
}
// notify other threads that the destruction is done
{
@ -573,16 +579,21 @@ int main(int, char**) {
cycle_cv_.notify_all();
}
TracyMessageL("waiting for all tasks");
for (;;) {
std::unique_lock<std::shared_mutex> sk {task_mtx_};
if (!mainq_.size() && !subq_.size() && !asyncq_.size() && !glq_.size()) {
break;
{
ZoneScopedN("wait for all tasks");
for (;;) {
{
ZoneScopedN("check remained tasks");
std::unique_lock<std::shared_mutex> sk {task_mtx_};
if (!mainq_.size() && !subq_.size() && !asyncq_.size() && !glq_.size()) {
break;
}
}
std::this_thread::sleep_for(30ms);
}
std::this_thread::sleep_for(30ms);
}
TracyMessageL("exitting SyncWorker and AsyncWorker");
// request SyncWorker and AsyncWorker to exit
{
alive_ = false;
cycle_ = kSyncUpdate;
@ -591,14 +602,16 @@ int main(int, char**) {
}
for (auto& th : th_async) th.join();
th_worker.join();
TracyMessageL("SyncWorker and AsyncWorker exited");
TracyMessageL("exitting GLWorker");
// wake up GLWorker to exit
{
cycle_ = kSyncDraw;
std::unique_lock<std::mutex> k {cycle_mtx_};
cycle_cv_.notify_all();
}
th_gl.join();
TracyMessageL("GLWorker exited");
{
ZoneScopedN("tear down everything");