Mathias Agopian | 35b48d1 | 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) { |
| 33 | int32_t v = htole32(value); |
| 34 | base[pos] = EVENT_TYPE_INT; |
| 35 | memcpy(&base[pos+1], &v, sizeof(int32_t)); |
| 36 | pos += 1+sizeof(int32_t); |
| 37 | } |
| 38 | |
| 39 | static inline |
| 40 | void writeInt64(uint8_t* base, size_t& pos, int64_t value) { |
| 41 | int64_t v = htole64(value); |
| 42 | base[pos] = EVENT_TYPE_LONG; |
| 43 | memcpy(&base[pos+1], &v, sizeof(int64_t)); |
| 44 | pos += 1+sizeof(int64_t); |
| 45 | } |
| 46 | |
| 47 | void GraphicLog::logImpl(int32_t tag, int32_t buffer) |
| 48 | { |
| 49 | uint8_t scratch[2 + 2 + sizeof(int32_t) + sizeof(int64_t)]; |
| 50 | size_t pos = 0; |
| 51 | scratch[pos++] = EVENT_TYPE_LIST; |
| 52 | scratch[pos++] = 2; |
| 53 | writeInt32(scratch, pos, buffer); |
| 54 | writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); |
| 55 | android_bWriteLog(tag, scratch, sizeof(scratch)); |
| 56 | } |
| 57 | |
| 58 | void GraphicLog::logImpl(int32_t tag, int32_t identity, int32_t buffer) |
| 59 | { |
| 60 | uint8_t scratch[2 + 3 + sizeof(int32_t) + sizeof(int32_t) + sizeof(int64_t)]; |
| 61 | size_t pos = 0; |
| 62 | scratch[pos++] = EVENT_TYPE_LIST; |
| 63 | scratch[pos++] = 3; |
| 64 | writeInt32(scratch, pos, buffer); |
| 65 | writeInt32(scratch, pos, identity); |
| 66 | writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) )); |
| 67 | android_bWriteLog(tag, scratch, sizeof(scratch)); |
| 68 | } |
| 69 | |
| 70 | GraphicLog::GraphicLog() |
| 71 | : mEnabled(0) |
| 72 | { |
| 73 | char property[PROPERTY_VALUE_MAX]; |
| 74 | if (property_get("debug.graphic_log", property, NULL) > 0) { |
| 75 | mEnabled = atoi(property); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void GraphicLog::setEnabled(bool enable) |
| 80 | { |
| 81 | mEnabled = enable; |
| 82 | } |
| 83 | |
| 84 | } |