-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from kroma-network/feat/integrate-perfetto-fo…
…r-profiling feat: integrate perfetto for profiling
- Loading branch information
Showing
53 changed files
with
722 additions
and
210 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "tachyon/base/profiler.h" | ||
|
||
PERFETTO_TRACK_EVENT_STATIC_STORAGE(); | ||
|
||
namespace tachyon::base { | ||
|
||
Profiler::Profiler() : Profiler(Options{}) {} | ||
|
||
Profiler::Profiler(const Options& options) | ||
: trace_filepath_(options.output_path), | ||
trace_file_(trace_filepath_, | ||
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE), | ||
max_size_kb_(options.max_size_kb) {} | ||
|
||
Profiler::~Profiler() { Stop(); } | ||
|
||
void Profiler::Init() { | ||
perfetto::TracingInitArgs args; | ||
args.backends |= perfetto::kInProcessBackend; | ||
perfetto::Tracing::Initialize(args); | ||
perfetto::TrackEvent::Register(); | ||
} | ||
|
||
void Profiler::DisableCategories(std::string_view category) { | ||
track_event_cfg_.add_disabled_categories(std::string(category)); | ||
} | ||
|
||
void Profiler::EnableCategories(std::string_view category) { | ||
track_event_cfg_.add_enabled_categories(std::string(category)); | ||
} | ||
|
||
void Profiler::Start() { | ||
perfetto::TraceConfig cfg; | ||
cfg.add_buffers()->set_size_kb(max_size_kb_); | ||
|
||
auto* ds_cfg = cfg.add_data_sources()->mutable_config(); | ||
ds_cfg->set_name("track_event"); | ||
ds_cfg->set_track_event_config_raw(track_event_cfg_.SerializeAsString()); | ||
|
||
tracing_session_ = perfetto::Tracing::NewTrace(); | ||
tracing_session_->Setup(cfg, trace_file_.GetPlatformFile()); | ||
tracing_session_->StartBlocking(); | ||
} | ||
|
||
void Profiler::Stop() { tracing_session_->StopBlocking(); } | ||
|
||
} // namespace tachyon::base |
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,56 @@ | ||
#ifndef TACHYON_BASE_PROFILER_H_ | ||
#define TACHYON_BASE_PROFILER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "third_party/perfetto/perfetto.h" | ||
|
||
#include "tachyon/base/files/file.h" | ||
#include "tachyon/export.h" | ||
|
||
PERFETTO_DEFINE_CATEGORIES( | ||
perfetto::Category("Utils").SetDescription("Base utility functions"), | ||
perfetto::Category("Subtask").SetDescription( | ||
"Subtask within a bigger task"), | ||
perfetto::Category("MSM").SetDescription( | ||
"Multi Scalar Multiplication operations"), | ||
perfetto::Category("ProofGeneration") | ||
.SetDescription("The proof generation process"), | ||
perfetto::Category("ProofVerification") | ||
.SetDescription("The proof verification process"), | ||
perfetto::Category("EvaluationDomain") | ||
.SetDescription("Evaluation Domain operations")); | ||
|
||
namespace tachyon::base { | ||
|
||
class TACHYON_EXPORT Profiler { | ||
public: | ||
struct Options { | ||
constexpr static size_t kDefaultMaxSizeKB = 1e6; | ||
|
||
base::FilePath output_path = base::FilePath("/tmp/tachyon.perfetto-trace"); | ||
size_t max_size_kb = kDefaultMaxSizeKB; | ||
}; | ||
|
||
Profiler(); | ||
explicit Profiler(const Options& options); | ||
~Profiler(); | ||
|
||
void Init(); | ||
void DisableCategories(std::string_view category); | ||
void EnableCategories(std::string_view category); | ||
void Start(); | ||
void Stop(); | ||
|
||
private: | ||
perfetto::protos::gen::TrackEventConfig track_event_cfg_; | ||
std::unique_ptr<perfetto::TracingSession> tracing_session_; | ||
FilePath trace_filepath_; | ||
File trace_file_; | ||
size_t max_size_kb_; | ||
}; | ||
|
||
} // namespace tachyon::base | ||
|
||
#endif // TACHYON_BASE_PROFILER_H_ |
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
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
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.