1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #define LOG_TAG "dumpstate" 18 19 #include "DumpstateSectionReporter.h" 20 21 namespace android { 22 namespace os { 23 namespace dumpstate { 24 25 DumpstateSectionReporter::DumpstateSectionReporter(const std::string& title, 26 sp<android::os::IDumpstateListener> listener, 27 bool sendReport) 28 : title_(title), listener_(listener), sendReport_(sendReport), status_(OK), size_(-1) { 29 started_ = std::chrono::steady_clock::now(); 30 } 31 32 DumpstateSectionReporter::~DumpstateSectionReporter() { 33 if ((listener_ != nullptr) && (sendReport_)) { 34 auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( 35 std::chrono::steady_clock::now() - started_); 36 listener_->onSectionComplete(title_, status_, size_, (int32_t)elapsed.count()); 37 } 38 } 39 40 } // namespace dumpstate 41 } // namespace os 42 } // namespace android 43