blob: 7ba2779d1cfd0cf20acc798e1f07dacacab0fe6f [file] [log] [blame]
Mathias Agopian04262e92010-09-13 22:57:58 -07001/*
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
27namespace android {
28
29ANDROID_SINGLETON_STATIC_INSTANCE(GraphicLog)
30
31static inline
32void writeInt32(uint8_t* base, size_t& pos, int32_t value) {
Brian Carlstromdbb7b6d2010-09-16 16:28:13 -070033#ifdef HAVE_LITTLE_ENDIAN
34 int32_t v = value;
35#else
Mathias Agopian04262e92010-09-13 22:57:58 -070036 int32_t v = htole32(value);
Brian Carlstromdbb7b6d2010-09-16 16:28:13 -070037#endif
Mathias Agopian04262e92010-09-13 22:57:58 -070038 base[pos] = EVENT_TYPE_INT;
39 memcpy(&base[pos+1], &v, sizeof(int32_t));
40 pos += 1+sizeof(int32_t);
41}
42
43static inline
44void writeInt64(uint8_t* base, size_t& pos, int64_t value) {
Brian Carlstromdbb7b6d2010-09-16 16:28:13 -070045#ifdef HAVE_LITTLE_ENDIAN
46 int64_t v = value;
47#else
Mathias Agopian04262e92010-09-13 22:57:58 -070048 int64_t v = htole64(value);
Brian Carlstromdbb7b6d2010-09-16 16:28:13 -070049#endif
Mathias Agopian04262e92010-09-13 22:57:58 -070050 base[pos] = EVENT_TYPE_LONG;
51 memcpy(&base[pos+1], &v, sizeof(int64_t));
52 pos += 1+sizeof(int64_t);
53}
54
55void 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
66void 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
78GraphicLog::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
87void GraphicLog::setEnabled(bool enable)
88{
89 mEnabled = enable;
90}
91
92}