• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef RESULT_DEMUXER_H
16 #define RESULT_DEMUXER_H
17 
18 #include <chrono>
19 #include <thread>
20 
21 #include "logging.h"
22 #include "nocopyable.h"
23 #include "profiler_data_repeater.h"
24 #include "profiler_service.grpc.pb.h"
25 #include "trace_file_writer.h"
26 
27 class ResultDemuxer {
28 public:
29     explicit ResultDemuxer(const ProfilerDataRepeaterPtr& dataRepeater);
30 
31     ~ResultDemuxer();
32 
33     void SetTraceWriter(const TraceFileWriterPtr& traceWriter);
34 
35     void SetFlushInterval(std::chrono::milliseconds interval);
36 
37     bool StartTakeResults();
38 
39     bool StopTakeResults();
40 
41 private:
42     void TakeResults();
43 
44 private:
45     TraceFileWriterPtr traceWriter_ = nullptr;
46     ProfilerDataRepeaterPtr dataRepeater_ = nullptr;
47     std::chrono::milliseconds flushInterval_ {};
48     std::chrono::steady_clock::time_point lastFlushTime_ {};
49     std::thread demuxerThread_ {};
50 
51     DISALLOW_COPY_AND_MOVE(ResultDemuxer);
52 };
53 
54 #endif // RESULT_DEMUXER_H