Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 1 | /* |
| 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 Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 17 | #pragma once |
| 18 | |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 19 | #include <utils/Errors.h> |
| 20 | #include <utils/Singleton.h> |
| 21 | |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 22 | #include <cstdint> |
| 23 | #include <string_view> |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 24 | |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 25 | namespace android { |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 26 | |
| 27 | class EventLog : public Singleton<EventLog> { |
| 28 | |
| 29 | public: |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 30 | static void logFrameDurations(const std::string_view& name, const int32_t* durations, |
| 31 | size_t numDurations); |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 32 | |
| 33 | protected: |
| 34 | EventLog(); |
| 35 | |
| 36 | private: |
| 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 Hsieh | 342b760 | 2016-09-01 11:34:16 -0700 | [diff] [blame] | 52 | explicit TagBuffer(int32_t tag); |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 53 | |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 54 | void startList(int8_t count); |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 55 | void endList(); |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 56 | |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 57 | void writeInt32(int32_t); |
| 58 | void writeInt64(int64_t); |
| 59 | void writeString(const std::string_view&); |
| 60 | |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 61 | void log(); |
| 62 | }; |
| 63 | |
| 64 | friend class Singleton<EventLog>; |
| 65 | EventLog(const EventLog&); |
| 66 | EventLog& operator =(const EventLog&); |
| 67 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 68 | enum { LOGTAG_SF_FRAME_DUR = 60100 }; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 69 | void doLogFrameDurations(const std::string_view& name, const int32_t* durations, |
| 70 | size_t numDurations); |
Mathias Agopian | 85cce37 | 2013-06-04 21:50:31 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 73 | } // namespace android |