blob: ee3587ef8aa15149b8d4ad466647c4d259364e20 [file] [log] [blame]
Mathias Agopian85cce372013-06-04 21:50:31 -07001/*
2 * Copyright 2013 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
Dominik Laskowski87a07e42019-10-10 20:38:02 -070017#pragma once
18
Mathias Agopian85cce372013-06-04 21:50:31 -070019#include <utils/Errors.h>
20#include <utils/Singleton.h>
21
Dominik Laskowski87a07e42019-10-10 20:38:02 -070022#include <cstdint>
23#include <string_view>
Mathias Agopian85cce372013-06-04 21:50:31 -070024
Mathias Agopian85cce372013-06-04 21:50:31 -070025namespace android {
Mathias Agopian85cce372013-06-04 21:50:31 -070026
27class EventLog : public Singleton<EventLog> {
28
29public:
Dominik Laskowski87a07e42019-10-10 20:38:02 -070030 static void logFrameDurations(const std::string_view& name, const int32_t* durations,
31 size_t numDurations);
Mathias Agopian85cce372013-06-04 21:50:31 -070032
33protected:
34 EventLog();
35
36private:
37 /*
38 * EventLogBuffer is a helper class to construct an in-memory event log
39 * tag. In this version the buffer is not dynamic, so write operation can
40 * fail if there is not enough space in the temporary buffer.
41 * Once constructed, the buffer can be logger by calling the log()
42 * method.
43 */
44
45 class TagBuffer {
46 enum { STORAGE_MAX_SIZE = 128 };
47 int32_t mPos;
48 int32_t mTag;
49 bool mOverflow;
50 char mStorage[STORAGE_MAX_SIZE];
51 public:
Chih-Hung Hsieh342b7602016-09-01 11:34:16 -070052 explicit TagBuffer(int32_t tag);
Mathias Agopian85cce372013-06-04 21:50:31 -070053
Mathias Agopian85cce372013-06-04 21:50:31 -070054 void startList(int8_t count);
Mathias Agopian85cce372013-06-04 21:50:31 -070055 void endList();
Mathias Agopian85cce372013-06-04 21:50:31 -070056
Dominik Laskowski87a07e42019-10-10 20:38:02 -070057 void writeInt32(int32_t);
58 void writeInt64(int64_t);
59 void writeString(const std::string_view&);
60
Mathias Agopian85cce372013-06-04 21:50:31 -070061 void log();
62 };
63
64 friend class Singleton<EventLog>;
65 EventLog(const EventLog&);
66 EventLog& operator =(const EventLog&);
67
Jamie Gennis6547ff42013-07-16 20:12:42 -070068 enum { LOGTAG_SF_FRAME_DUR = 60100 };
Dominik Laskowski87a07e42019-10-10 20:38:02 -070069 void doLogFrameDurations(const std::string_view& name, const int32_t* durations,
70 size_t numDurations);
Mathias Agopian85cce372013-06-04 21:50:31 -070071};
72
Dominik Laskowski87a07e42019-10-10 20:38:02 -070073} // namespace android