123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- #ifndef CNSTREAM_FRAMEWORK_CORE_INCLUDE_PROFILER_PIPELINE_PROFILER_HPP_
- #define CNSTREAM_FRAMEWORK_CORE_INCLUDE_PROFILER_PIPELINE_PROFILER_HPP_
- #include <memory>
- #include <string>
- #include <vector>
- #include <unordered_map>
- #include "cnstream_common.hpp"
- #include "cnstream_config.hpp"
- #include "profiler/process_profiler.hpp"
- #include "profiler/profile.hpp"
- #include "profiler/trace.hpp"
- namespace cnstream {
- class Module;
- class ModuleProfiler;
- static constexpr char kOVERALL_PROCESS_NAME[] = "OVERALL";
- class PipelineProfiler : private NonCopyable {
- public:
-
- PipelineProfiler(const ProfilerConfig& config,
- const std::string& pipeline_name,
- const std::vector<std::shared_ptr<Module>>& modules);
-
- std::string GetName() const;
-
- ProfilerConfig GetConfig() const;
-
- PipelineTracer* GetTracer() const;
-
- ModuleProfiler* GetModuleProfiler(const std::string& module_name) const;
-
- PipelineProfile GetProfile();
-
- PipelineProfile GetProfile(const Time& start, const Time& end);
-
- PipelineProfile GetProfileBefore(const Time& end, const Duration& duration);
-
- PipelineProfile GetProfileAfter(const Time& start, const Duration& duration);
-
- void RecordInput(const RecordKey& key);
-
- void RecordOutput(const RecordKey& key);
-
- void OnStreamEos(const std::string& stream_name);
- private:
- ProfilerConfig config_;
- std::string pipeline_name_;
- std::unordered_map<std::string, std::unique_ptr<ModuleProfiler>> module_profilers_;
- std::unique_ptr<ProcessProfiler> overall_profiler_;
- std::unique_ptr<PipelineTracer> tracer_;
- };
- inline std::string PipelineProfiler::GetName() const {
- return pipeline_name_;
- }
- inline ProfilerConfig PipelineProfiler::GetConfig() const {
- return config_;
- }
- inline PipelineTracer* PipelineProfiler::GetTracer() const {
- return tracer_.get();
- }
- inline PipelineProfile PipelineProfiler::GetProfileBefore(const Time& end, const Duration& duration) {
- return GetProfile(std::chrono::time_point_cast<Clock::duration>(end - duration), end);
- }
- inline PipelineProfile PipelineProfiler::GetProfileAfter(const Time& start, const Duration& duration) {
- return GetProfile(start, std::chrono::time_point_cast<Clock::duration>(start + duration));
- }
- inline void PipelineProfiler::RecordInput(const RecordKey& key) {
- overall_profiler_->RecordStart(key);
- }
- inline void PipelineProfiler::RecordOutput(const RecordKey& key) {
- overall_profiler_->RecordEnd(key);
- }
- inline void PipelineProfiler::OnStreamEos(const std::string& stream_name) {
- overall_profiler_->OnStreamEos(stream_name);
- }
- }
- #endif
|