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 16 17 #ifndef STACK_WRITER_H 18 #define STACK_WRITER_H 19 20 #include <atomic> 21 #include <chrono> 22 #include <memory> 23 #include "event_notifier.h" 24 25 #include "share_memory_allocator.h" 26 #include "writer.h" 27 28 class StackWriter : public Writer { 29 public: 30 StackWriter(std::string name, 31 uint32_t size, 32 int smbFd, 33 int eventFd); 34 ~StackWriter(); 35 long Write(const void* data, size_t size) override; 36 bool Flush() override; 37 38 private: 39 void DoStats(long bytes); 40 void Report() const; 41 42 private: 43 std::string pluginName_; 44 std::shared_ptr<ShareMemoryBlock> shareMemoryBlock_; 45 EventNotifierPtr eventNotifier_ = nullptr; 46 std::chrono::steady_clock::time_point lastFlushTime_; 47 std::atomic<uint64_t> bytesCount_ = 0; 48 std::atomic<uint32_t> bytesPending_ = 0; 49 std::atomic<uint64_t> writeCount_ = 0; 50 std::atomic<uint32_t> flushCount_ = 0; 51 }; 52 53 54 #endif // STACK_WRITER_H