Trace.h revision fcb349ff75272c802519a20abc0e083c35bbe8cf
12ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis/* 22ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * Copyright (C) 2012 The Android Open Source Project 32ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * 42ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * Licensed under the Apache License, Version 2.0 (the "License"); 52ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * you may not use this file except in compliance with the License. 62ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * You may obtain a copy of the License at 72ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * 82ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * http://www.apache.org/licenses/LICENSE-2.0 92ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * 102ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * Unless required by applicable law or agreed to in writing, software 112ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * distributed under the License is distributed on an "AS IS" BASIS, 122ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * See the License for the specific language governing permissions and 142ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis * limitations under the License. 152ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis */ 162ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 172ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#ifndef ANDROID_TRACE_H 182ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#define ANDROID_TRACE_H 192ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 202ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <fcntl.h> 212ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <stdint.h> 222ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <stdio.h> 232ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <string.h> 242ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <sys/stat.h> 252ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <sys/types.h> 262ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <unistd.h> 272ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 282ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <cutils/compiler.h> 292ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#include <utils/threads.h> 305b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray#include <cutils/trace.h> 312ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 325b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray// See <cutils/trace.h> for more ATRACE_* macros. 332ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 34fcb349ff75272c802519a20abc0e083c35bbe8cfAlex Ray// ATRACE_NAME traces the beginning and end of the current scope. To trace 35fcb349ff75272c802519a20abc0e083c35bbe8cfAlex Ray// the correct start and end times this macro should be declared first in the 36fcb349ff75272c802519a20abc0e083c35bbe8cfAlex Ray// scope body. 373fc49adfd2887d01e54c4ad6a62eae5383101f62Romain Guy#define ATRACE_NAME(name) android::ScopedTrace ___tracer(ATRACE_TAG, name) 38fcb349ff75272c802519a20abc0e083c35bbe8cfAlex Ray// ATRACE_CALL is an ATRACE_NAME that uses the current function name. 39fcb349ff75272c802519a20abc0e083c35bbe8cfAlex Ray#define ATRACE_CALL() ATRACE_NAME(__FUNCTION__) 403fc49adfd2887d01e54c4ad6a62eae5383101f62Romain Guy 412ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennisnamespace android { 422ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 432ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennisclass ScopedTrace { 442ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennispublic: 455b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Rayinline ScopedTrace(uint64_t tag, const char* name) 465b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray : mTag(tag) { 475b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray atrace_begin(mTag,name); 485b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray} 492ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 505b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Rayinline ~ScopedTrace() { 515b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray atrace_end(mTag); 525b2d36e38adcc09e72f81b06c324bf3c5c92e043Alex Ray} 532ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 542ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennisprivate: 552ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis uint64_t mTag; 562ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis}; 572ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 582ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis}; // namespace android 592ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis 602ccfe1a0606f59b5cefd177f9dd5c837d0ea2d0bJamie Gennis#endif // ANDROID_TRACE_H 61