104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian/* 204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * Copyright (C) 2010 The Android Open Source Project 304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * 404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * you may not use this file except in compliance with the License. 604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * You may obtain a copy of the License at 704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * 804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * 1004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * Unless required by applicable law or agreed to in writing, software 1104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 1204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * See the License for the specific language governing permissions and 1404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian * limitations under the License. 1504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian */ 1604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 1704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 1804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <stdlib.h> 1904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <unistd.h> 2004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <cutils/log.h> 2104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <cutils/properties.h> 2204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <utils/Endian.h> 2304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <utils/Timers.h> 2404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 2504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian#include <ui/GraphicLog.h> 2604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 2704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopiannamespace android { 2804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 2904262e9f842edf20168399b6a70f0d67e518fe69Mathias AgopianANDROID_SINGLETON_STATIC_INSTANCE(GraphicLog) 3004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 3104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianstatic inline 3204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianvoid writeInt32(uint8_t* base, size_t& pos, int32_t value) { 33dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#ifdef HAVE_LITTLE_ENDIAN 34dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom int32_t v = value; 35dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#else 3604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian int32_t v = htole32(value); 37dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#endif 3804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian base[pos] = EVENT_TYPE_INT; 3904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian memcpy(&base[pos+1], &v, sizeof(int32_t)); 4004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian pos += 1+sizeof(int32_t); 4104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 4204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 4304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianstatic inline 4404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianvoid writeInt64(uint8_t* base, size_t& pos, int64_t value) { 45dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#ifdef HAVE_LITTLE_ENDIAN 46dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom int64_t v = value; 47dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#else 4804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian int64_t v = htole64(value); 49dbb7b6da080782d032251c1ab181145eaa3fc2b2Brian Carlstrom#endif 5004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian base[pos] = EVENT_TYPE_LONG; 5104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian memcpy(&base[pos+1], &v, sizeof(int64_t)); 5204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian pos += 1+sizeof(int64_t); 5304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 5404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 5504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianvoid GraphicLog::logImpl(int32_t tag, int32_t buffer) 5604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian{ 5704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian uint8_t scratch[2 + 2 + sizeof(int32_t) + sizeof(int64_t)]; 5804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian size_t pos = 0; 5904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian scratch[pos++] = EVENT_TYPE_LIST; 6004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian scratch[pos++] = 2; 6104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian writeInt32(scratch, pos, buffer); 6204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); 6304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian android_bWriteLog(tag, scratch, sizeof(scratch)); 6404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 6504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 6604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianvoid GraphicLog::logImpl(int32_t tag, int32_t identity, int32_t buffer) 6704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian{ 6804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian uint8_t scratch[2 + 3 + sizeof(int32_t) + sizeof(int32_t) + sizeof(int64_t)]; 6904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian size_t pos = 0; 7004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian scratch[pos++] = EVENT_TYPE_LIST; 7104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian scratch[pos++] = 3; 7204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian writeInt32(scratch, pos, buffer); 7304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian writeInt32(scratch, pos, identity); 7404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); 7504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian android_bWriteLog(tag, scratch, sizeof(scratch)); 7604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 7704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 7804262e9f842edf20168399b6a70f0d67e518fe69Mathias AgopianGraphicLog::GraphicLog() 7904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian : mEnabled(0) 8004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian{ 8104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian char property[PROPERTY_VALUE_MAX]; 8204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian if (property_get("debug.graphic_log", property, NULL) > 0) { 8304262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian mEnabled = atoi(property); 8404262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian } 8504262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 8604262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 8704262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopianvoid GraphicLog::setEnabled(bool enable) 8804262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian{ 8904262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian mEnabled = enable; 9004262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 9104262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian 9204262e9f842edf20168399b6a70f0d67e518fe69Mathias Agopian} 93