blob: b0003ded2ad0a080adea40827bb203ab1444459b [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
Mark Salyzyn1a240b42014-06-12 11:16:16 -070026#include <private/android_filesystem_config.h>
27
Mark Salyzyn0175b072014-02-26 09:50:16 -080028#include "LogBufferElement.h"
29#include "LogTimes.h"
Mark Salyzyn34facab2014-02-06 14:48:50 -080030#include "LogStatistics.h"
Mark Salyzyndfa7a072014-02-11 12:29:31 -080031#include "LogWhiteBlackList.h"
Mark Salyzyn0175b072014-02-26 09:50:16 -080032
33typedef android::List<LogBufferElement *> LogBufferElementCollection;
34
35class LogBuffer {
36 LogBufferElementCollection mLogElements;
37 pthread_mutex_t mLogElementsLock;
38
Mark Salyzyn34facab2014-02-06 14:48:50 -080039 LogStatistics stats;
Mark Salyzyne457b742014-02-19 17:18:31 -080040
Mark Salyzyndfa7a072014-02-11 12:29:31 -080041 PruneList mPrune;
42
43 unsigned long mMaxSize[LOG_ID_MAX];
Mark Salyzyndfa7a072014-02-11 12:29:31 -080044
Mark Salyzyn0175b072014-02-26 09:50:16 -080045public:
46 LastLogTimes &mTimes;
47
48 LogBuffer(LastLogTimes *times);
49
Mark Salyzyn7e2f83c2014-03-05 07:41:49 -080050 void log(log_id_t log_id, log_time realtime,
Mark Salyzynb992d0d2014-03-20 16:09:38 -070051 uid_t uid, pid_t pid, pid_t tid,
52 const char *msg, unsigned short len);
Mark Salyzyn7e2f83c2014-03-05 07:41:49 -080053 log_time flushTo(SocketClient *writer, const log_time start,
54 bool privileged,
55 bool (*filter)(const LogBufferElement *element, void *arg) = NULL,
56 void *arg = NULL);
Mark Salyzyn0175b072014-02-26 09:50:16 -080057
Mark Salyzyn1a240b42014-06-12 11:16:16 -070058 void clear(log_id_t id, uid_t uid = AID_ROOT);
Mark Salyzyn0175b072014-02-26 09:50:16 -080059 unsigned long getSize(log_id_t id);
Mark Salyzyndfa7a072014-02-11 12:29:31 -080060 int setSize(log_id_t id, unsigned long size);
Mark Salyzyn0175b072014-02-26 09:50:16 -080061 unsigned long getSizeUsed(log_id_t id);
Mark Salyzyn34facab2014-02-06 14:48:50 -080062 // *strp uses malloc, use free to release.
Mark Salyzyndfa7a072014-02-11 12:29:31 -080063 void formatStatistics(char **strp, uid_t uid, unsigned int logMask);
64
Mark Salyzynf5fc5092014-09-21 14:22:18 -070065 void enableStatistics() {
66 stats.enableStatistics();
67 }
68
Mark Salyzyndfa7a072014-02-11 12:29:31 -080069 int initPrune(char *cp) { return mPrune.init(cp); }
70 // *strp uses malloc, use free to release.
71 void formatPrune(char **strp) { mPrune.format(strp); }
Mark Salyzyn0175b072014-02-26 09:50:16 -080072
Mark Salyzyn9a038632014-04-07 07:05:40 -070073 // helper
74 char *pidToName(pid_t pid) { return stats.pidToName(pid); }
Mark Salyzyn4ba03872014-04-07 07:15:33 -070075 uid_t pidToUid(pid_t pid) { return stats.pidToUid(pid); }
Mark Salyzyn9a038632014-04-07 07:05:40 -070076
Mark Salyzyn0175b072014-02-26 09:50:16 -080077private:
78 void maybePrune(log_id_t id);
Mark Salyzyn1a240b42014-06-12 11:16:16 -070079 void prune(log_id_t id, unsigned long pruneRows, uid_t uid = AID_ROOT);
Mark Salyzyn0175b072014-02-26 09:50:16 -080080
81};
82
Mark Salyzyn34facab2014-02-06 14:48:50 -080083#endif // _LOGD_LOG_BUFFER_H__