Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | #include <cutils/log.h> |
| 21 | #include <cutils/properties.h> |
| 22 | #include <utils/Endian.h> |
| 23 | #include <utils/Timers.h> |
| 24 | |
| 25 | #include <ui/GraphicLog.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | ANDROID_SINGLETON_STATIC_INSTANCE(GraphicLog) |
| 30 | |
| 31 | static inline |
| 32 | void writeInt32(uint8_t* base, size_t& pos, int32_t value) { |
Brian Carlstrom | dbb7b6d | 2010-09-16 16:28:13 -0700 | [diff] [blame] | 33 | #ifdef HAVE_LITTLE_ENDIAN |
| 34 | int32_t v = value; |
| 35 | #else |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 36 | int32_t v = htole32(value); |
Brian Carlstrom | dbb7b6d | 2010-09-16 16:28:13 -0700 | [diff] [blame] | 37 | #endif |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 38 | base[pos] = EVENT_TYPE_INT; |
| 39 | memcpy(&base[pos+1], &v, sizeof(int32_t)); |
| 40 | pos += 1+sizeof(int32_t); |
| 41 | } |
| 42 | |
| 43 | static inline |
| 44 | void writeInt64(uint8_t* base, size_t& pos, int64_t value) { |
Brian Carlstrom | dbb7b6d | 2010-09-16 16:28:13 -0700 | [diff] [blame] | 45 | #ifdef HAVE_LITTLE_ENDIAN |
| 46 | int64_t v = value; |
| 47 | #else |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 48 | int64_t v = htole64(value); |
Brian Carlstrom | dbb7b6d | 2010-09-16 16:28:13 -0700 | [diff] [blame] | 49 | #endif |
Mathias Agopian | 04262e9 | 2010-09-13 22:57:58 -0700 | [diff] [blame] | 50 | base[pos] = EVENT_TYPE_LONG; |
| 51 | memcpy(&base[pos+1], &v, sizeof(int64_t)); |
| 52 | pos += 1+sizeof(int64_t); |
| 53 | } |
| 54 | |
| 55 | void GraphicLog::logImpl(int32_t tag, int32_t buffer) |
| 56 | { |
| 57 | uint8_t scratch[2 + 2 + sizeof(int32_t) + sizeof(int64_t)]; |
| 58 | size_t pos = 0; |
| 59 | scratch[pos++] = EVENT_TYPE_LIST; |
| 60 | scratch[pos++] = 2; |
| 61 | writeInt32(scratch, pos, buffer); |
| 62 | writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); |
| 63 | android_bWriteLog(tag, scratch, sizeof(scratch)); |
| 64 | } |
| 65 | |
| 66 | void GraphicLog::logImpl(int32_t tag, int32_t identity, int32_t buffer) |
| 67 | { |
| 68 | uint8_t scratch[2 + 3 + sizeof(int32_t) + sizeof(int32_t) + sizeof(int64_t)]; |
| 69 | size_t pos = 0; |
| 70 | scratch[pos++] = EVENT_TYPE_LIST; |
| 71 | scratch[pos++] = 3; |
| 72 | writeInt32(scratch, pos, buffer); |
| 73 | writeInt32(scratch, pos, identity); |
| 74 | writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); |
| 75 | android_bWriteLog(tag, scratch, sizeof(scratch)); |
| 76 | } |
| 77 | |
| 78 | GraphicLog::GraphicLog() |
| 79 | : mEnabled(0) |
| 80 | { |
| 81 | char property[PROPERTY_VALUE_MAX]; |
| 82 | if (property_get("debug.graphic_log", property, NULL) > 0) { |
| 83 | mEnabled = atoi(property); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void GraphicLog::setEnabled(bool enable) |
| 88 | { |
| 89 | mEnabled = enable; |
| 90 | } |
| 91 | |
| 92 | } |