blob: 7c57660525727e42a0129fc998e3edce3f313a53 [file] [log] [blame]
Mark Salyzyn0175b072014-02-26 09:50:16 -08001/*
2 * Copyright (C) 2012-2014 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#ifndef _LOGD_LOG_BUFFER_H__
18#define _LOGD_LOG_BUFFER_H__
19
20#include <sys/types.h>
21
22#include <log/log.h>
23#include <sysutils/SocketClient.h>
24#include <utils/List.h>
25
26#include "LogBufferElement.h"
27#include "LogTimes.h"
Mark Salyzyn34facab2014-02-06 14:48:50 -080028#include "LogStatistics.h"
Mark Salyzyndfa7a072014-02-11 12:29:31 -080029#include "LogWhiteBlackList.h"
Mark Salyzyn0175b072014-02-26 09:50:16 -080030
31typedef android::List<LogBufferElement *> LogBufferElementCollection;
32
33class LogBuffer {
34 LogBufferElementCollection mLogElements;
35 pthread_mutex_t mLogElementsLock;
36
Mark Salyzyn34facab2014-02-06 14:48:50 -080037 LogStatistics stats;
Mark Salyzyn0175b072014-02-26 09:50:16 -080038
Mark Salyzyne457b742014-02-19 17:18:31 -080039 bool dgram_qlen_statistics;
40
Mark Salyzyndfa7a072014-02-11 12:29:31 -080041#ifdef USERDEBUG_BUILD
42 PruneList mPrune;
43
44 unsigned long mMaxSize[LOG_ID_MAX];
45#endif
46
Mark Salyzyn0175b072014-02-26 09:50:16 -080047public:
48 LastLogTimes &mTimes;
49
50 LogBuffer(LastLogTimes *times);
51
Mark Salyzyn7e2f83c2014-03-05 07:41:49 -080052 void log(log_id_t log_id, log_time realtime,
Mark Salyzynb992d0d2014-03-20 16:09:38 -070053 uid_t uid, pid_t pid, pid_t tid,
54 const char *msg, unsigned short len);
Mark Salyzyn7e2f83c2014-03-05 07:41:49 -080055 log_time flushTo(SocketClient *writer, const log_time start,
56 bool privileged,
57 bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
58 void *arg = NULL);
Mark Salyzyn0175b072014-02-26 09:50:16 -080059
60 void clear(log_id_t id);
61 unsigned long getSize(log_id_t id);
Mark Salyzyndfa7a072014-02-11 12:29:31 -080062#ifdef USERDEBUG_BUILD
63 int setSize(log_id_t id, unsigned long size);
64#endif
Mark Salyzyn0175b072014-02-26 09:50:16 -080065 unsigned long getSizeUsed(log_id_t id);
Mark Salyzyn34facab2014-02-06 14:48:50 -080066 // *strp uses malloc, use free to release.
Mark Salyzyndfa7a072014-02-11 12:29:31 -080067 void formatStatistics(char **strp, uid_t uid, unsigned int logMask);
68
Mark Salyzyne457b742014-02-19 17:18:31 -080069 void enableDgramQlenStatistics() {
70 stats.enableDgramQlenStatistics();
71 dgram_qlen_statistics = true;
72 }
73
Mark Salyzyndfa7a072014-02-11 12:29:31 -080074#ifdef USERDEBUG_BUILD
75 int initPrune(char *cp) { return mPrune.init(cp); }
76 // *strp uses malloc, use free to release.
77 void formatPrune(char **strp) { mPrune.format(strp); }
78#endif
Mark Salyzyn0175b072014-02-26 09:50:16 -080079
Mark Salyzyn9a038632014-04-07 07:05:40 -070080 // helper
81 char *pidToName(pid_t pid) { return stats.pidToName(pid); }
82
Mark Salyzyn0175b072014-02-26 09:50:16 -080083private:
84 void maybePrune(log_id_t id);
85 void prune(log_id_t id, unsigned long pruneRows);
86
87};
88
Mark Salyzyn34facab2014-02-06 14:48:50 -080089#endif // _LOGD_LOG_BUFFER_H__