16f12d573251528086636707dde2fb01a8b7199b8Jeff Brown/*
26f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * Copyright (C) 2012 The Android Open Source Project
36f12d573251528086636707dde2fb01a8b7199b8Jeff Brown *
46f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License");
56f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * you may not use this file except in compliance with the License.
66f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * You may obtain a copy of the License at
76f12d573251528086636707dde2fb01a8b7199b8Jeff Brown *
86f12d573251528086636707dde2fb01a8b7199b8Jeff Brown *      http://www.apache.org/licenses/LICENSE-2.0
96f12d573251528086636707dde2fb01a8b7199b8Jeff Brown *
106f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * Unless required by applicable law or agreed to in writing, software
116f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS,
126f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * See the License for the specific language governing permissions and
146f12d573251528086636707dde2fb01a8b7199b8Jeff Brown * limitations under the License.
156f12d573251528086636707dde2fb01a8b7199b8Jeff Brown */
166f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
176f12d573251528086636707dde2fb01a8b7199b8Jeff Brown#define LOG_TAG "Log"
186f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
196f12d573251528086636707dde2fb01a8b7199b8Jeff Brown#include <utils/Log.h>
206f12d573251528086636707dde2fb01a8b7199b8Jeff Brown#include <utils/Timers.h>
216f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
226f12d573251528086636707dde2fb01a8b7199b8Jeff Brownnamespace android {
236f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
246f12d573251528086636707dde2fb01a8b7199b8Jeff BrownLogIfSlow::LogIfSlow(const char* tag, android_LogPriority priority,
256f12d573251528086636707dde2fb01a8b7199b8Jeff Brown        int timeoutMillis, const char* message) :
266f12d573251528086636707dde2fb01a8b7199b8Jeff Brown        mTag(tag), mPriority(priority), mTimeoutMillis(timeoutMillis), mMessage(message),
276f12d573251528086636707dde2fb01a8b7199b8Jeff Brown        mStart(systemTime(SYSTEM_TIME_BOOTTIME)) {
286f12d573251528086636707dde2fb01a8b7199b8Jeff Brown}
296f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
306f12d573251528086636707dde2fb01a8b7199b8Jeff BrownLogIfSlow::~LogIfSlow() {
316f12d573251528086636707dde2fb01a8b7199b8Jeff Brown    int durationMillis = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_BOOTTIME) - mStart);
326f12d573251528086636707dde2fb01a8b7199b8Jeff Brown    if (durationMillis > mTimeoutMillis) {
336f12d573251528086636707dde2fb01a8b7199b8Jeff Brown        LOG_PRI(mPriority, mTag, "%s: %dms", mMessage, durationMillis);
346f12d573251528086636707dde2fb01a8b7199b8Jeff Brown    }
356f12d573251528086636707dde2fb01a8b7199b8Jeff Brown}
366f12d573251528086636707dde2fb01a8b7199b8Jeff Brown
376f12d573251528086636707dde2fb01a8b7199b8Jeff Brown} // namespace android
38