summaryrefslogtreecommitdiffstats
path: root/libs/ui/GraphicLog.cpp
blob: 7ba2779d1cfd0cf20acc798e1f07dacacab0fe6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <stdlib.h>
#include <unistd.h>
#include <cutils/log.h>
#include <cutils/properties.h>
#include <utils/Endian.h>
#include <utils/Timers.h>

#include <ui/GraphicLog.h>

namespace android {

ANDROID_SINGLETON_STATIC_INSTANCE(GraphicLog)

static inline
void writeInt32(uint8_t* base, size_t& pos, int32_t value) {
#ifdef HAVE_LITTLE_ENDIAN
    int32_t v = value;
#else
    int32_t v = htole32(value);
#endif
    base[pos] = EVENT_TYPE_INT;
    memcpy(&base[pos+1], &v, sizeof(int32_t));
    pos += 1+sizeof(int32_t);
}

static inline
void writeInt64(uint8_t* base,  size_t& pos, int64_t value) {
#ifdef HAVE_LITTLE_ENDIAN
    int64_t v = value;
#else
    int64_t v = htole64(value);
#endif
    base[pos] = EVENT_TYPE_LONG;
    memcpy(&base[pos+1], &v, sizeof(int64_t));
    pos += 1+sizeof(int64_t);
}

void GraphicLog::logImpl(int32_t tag, int32_t buffer)
{
    uint8_t scratch[2 + 2 + sizeof(int32_t) + sizeof(int64_t)];
    size_t pos = 0;
    scratch[pos++] = EVENT_TYPE_LIST;
    scratch[pos++] = 2;
    writeInt32(scratch, pos, buffer);
    writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) ));
    android_bWriteLog(tag, scratch, sizeof(scratch));
}

void GraphicLog::logImpl(int32_t tag, int32_t identity, int32_t buffer)
{
    uint8_t scratch[2 + 3 + sizeof(int32_t) + sizeof(int32_t) + sizeof(int64_t)];
    size_t pos = 0;
    scratch[pos++] = EVENT_TYPE_LIST;
    scratch[pos++] = 3;
    writeInt32(scratch, pos, buffer);
    writeInt32(scratch, pos, identity);
    writeInt64(scratch, pos, ns2ms( systemTime( SYSTEM_TIME_MONOTONIC ) ));
    android_bWriteLog(tag, scratch, sizeof(scratch));
}

GraphicLog::GraphicLog()
    : mEnabled(0)
{
    char property[PROPERTY_VALUE_MAX];
    if (property_get("debug.graphic_log", property, NULL) > 0) {
        mEnabled = atoi(property);
    }
}

void GraphicLog::setEnabled(bool enable)
{
    mEnabled = enable;
}

}