2014-02-06 23:48:50 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LOGD_LOG_STATISTICS_H__
|
|
|
|
#define _LOGD_LOG_STATISTICS_H__
|
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <stdlib.h>
|
2014-02-06 23:48:50 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
#include <algorithm> // std::max
|
|
|
|
#include <string> // std::string
|
2015-05-19 18:12:30 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
#include <base/stringprintf.h>
|
2014-02-06 23:48:50 +01:00
|
|
|
#include <log/log.h>
|
2015-08-22 01:44:30 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
2015-03-10 21:51:35 +01:00
|
|
|
|
|
|
|
#include "LogBufferElement.h"
|
2015-08-28 17:02:59 +02:00
|
|
|
#include "LogUtils.h"
|
2014-02-06 23:48:50 +01:00
|
|
|
|
|
|
|
#define log_id_for_each(i) \
|
|
|
|
for (log_id_t i = LOG_ID_MIN; i < LOG_ID_MAX; i = (log_id_t) (i + 1))
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
class LogStatistics;
|
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
template <typename TKey, typename TEntry>
|
2015-05-19 18:12:30 +02:00
|
|
|
class LogHashtable {
|
|
|
|
|
|
|
|
std::unordered_map<TKey, TEntry> map;
|
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
public:
|
2015-05-19 18:12:30 +02:00
|
|
|
|
|
|
|
typedef typename std::unordered_map<TKey, TEntry>::iterator iterator;
|
2015-08-22 01:44:30 +02:00
|
|
|
typedef typename std::unordered_map<TKey, TEntry>::const_iterator const_iterator;
|
2015-05-19 18:12:30 +02:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
std::unique_ptr<const TEntry *[]> sort(size_t len) const {
|
|
|
|
if (!len) {
|
2015-03-16 16:26:05 +01:00
|
|
|
std::unique_ptr<const TEntry *[]> sorted(NULL);
|
|
|
|
return sorted;
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
const TEntry **retval = new const TEntry* [len];
|
|
|
|
memset(retval, 0, sizeof(*retval) * len);
|
2015-03-16 16:26:05 +01:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
for(const_iterator it = map.begin(); it != map.end(); ++it) {
|
2015-05-19 18:12:30 +02:00
|
|
|
const TEntry &entry = it->second;
|
2015-08-22 01:44:30 +02:00
|
|
|
size_t sizes = entry.getSizes();
|
|
|
|
ssize_t index = len - 1;
|
|
|
|
while ((!retval[index] || (sizes > retval[index]->getSizes()))
|
|
|
|
&& (--index >= 0))
|
2015-03-16 16:26:05 +01:00
|
|
|
;
|
2015-08-22 01:44:30 +02:00
|
|
|
if (++index < (ssize_t)len) {
|
|
|
|
size_t num = len - index - 1;
|
|
|
|
if (num) {
|
|
|
|
memmove(&retval[index + 1], &retval[index],
|
|
|
|
num * sizeof(retval[0]));
|
2015-03-16 16:26:05 +01:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
retval[index] = &entry;
|
2015-03-16 16:26:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::unique_ptr<const TEntry *[]> sorted(retval);
|
|
|
|
return sorted;
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline iterator add(TKey key, LogBufferElement *element) {
|
2015-05-19 18:12:30 +02:00
|
|
|
iterator it = map.find(key);
|
|
|
|
if (it == map.end()) {
|
2015-08-22 01:44:30 +02:00
|
|
|
it = map.insert(std::make_pair(key, TEntry(element))).first;
|
2015-05-19 18:12:30 +02:00
|
|
|
} else {
|
2015-08-22 01:44:30 +02:00
|
|
|
it->second.add(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-05-19 18:12:30 +02:00
|
|
|
return it;
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 18:12:30 +02:00
|
|
|
inline iterator add(TKey key) {
|
|
|
|
iterator it = map.find(key);
|
|
|
|
if (it == map.end()) {
|
|
|
|
it = map.insert(std::make_pair(key, TEntry(key))).first;
|
|
|
|
} else {
|
|
|
|
it->second.add(key);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-05-19 18:12:30 +02:00
|
|
|
return it;
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
void subtract(TKey key, LogBufferElement *element) {
|
2015-05-19 18:12:30 +02:00
|
|
|
iterator it = map.find(key);
|
2015-08-22 01:44:30 +02:00
|
|
|
if ((it != map.end()) && it->second.subtract(element)) {
|
2015-05-19 18:12:30 +02:00
|
|
|
map.erase(it);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void drop(TKey key, LogBufferElement *element) {
|
2015-05-19 18:12:30 +02:00
|
|
|
iterator it = map.find(key);
|
|
|
|
if (it != map.end()) {
|
2015-08-22 01:44:30 +02:00
|
|
|
it->second.drop(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 18:12:30 +02:00
|
|
|
inline iterator begin() { return map.begin(); }
|
2015-08-22 01:44:30 +02:00
|
|
|
inline const_iterator begin() const { return map.begin(); }
|
2015-05-19 18:12:30 +02:00
|
|
|
inline iterator end() { return map.end(); }
|
2015-08-22 01:44:30 +02:00
|
|
|
inline const_iterator end() const { return map.end(); }
|
|
|
|
|
|
|
|
std::string format(
|
|
|
|
const LogStatistics &stat,
|
|
|
|
uid_t uid,
|
|
|
|
const std::string &name = std::string(""),
|
|
|
|
log_id_t id = LOG_ID_MAX) const {
|
|
|
|
static const size_t maximum_sorted_entries = 32;
|
|
|
|
std::string output;
|
|
|
|
std::unique_ptr<const TEntry *[]> sorted = sort(maximum_sorted_entries);
|
|
|
|
|
|
|
|
if (!sorted.get()) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
bool headerPrinted = false;
|
|
|
|
for (size_t index = 0; index < maximum_sorted_entries; ++index) {
|
|
|
|
const TEntry *entry = sorted[index];
|
|
|
|
if (!entry) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entry->getSizes() <= (sorted[0]->getSizes() / 100)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((uid != AID_ROOT) && (uid != entry->getUid())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!headerPrinted) {
|
|
|
|
output += "\n\n";
|
|
|
|
output += entry->formatHeader(name, id);
|
|
|
|
headerPrinted = true;
|
|
|
|
}
|
|
|
|
output += entry->format(stat, id);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2015-03-16 16:26:05 +01:00
|
|
|
};
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
namespace EntryBaseConstants {
|
|
|
|
static constexpr size_t pruned_len = 14;
|
|
|
|
static constexpr size_t total_len = 80;
|
|
|
|
}
|
|
|
|
|
2015-04-13 23:24:45 +02:00
|
|
|
struct EntryBase {
|
2015-03-10 21:51:35 +01:00
|
|
|
size_t size;
|
2014-02-06 23:48:50 +01:00
|
|
|
|
2015-04-13 23:24:45 +02:00
|
|
|
EntryBase():size(0) { }
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBase(LogBufferElement *element):size(element->getMsgLen()) { }
|
2014-02-06 23:48:50 +01:00
|
|
|
|
2015-03-10 21:51:35 +01:00
|
|
|
size_t getSizes() const { return size; }
|
2015-04-13 23:24:45 +02:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(LogBufferElement *element) { size += element->getMsgLen(); }
|
|
|
|
inline bool subtract(LogBufferElement *element) {
|
|
|
|
size -= element->getMsgLen();
|
|
|
|
return !size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string formatLine(
|
|
|
|
const std::string &name,
|
|
|
|
const std::string &size,
|
|
|
|
const std::string &pruned) {
|
|
|
|
ssize_t drop_len = std::max(pruned.length() + 1,
|
|
|
|
EntryBaseConstants::pruned_len);
|
|
|
|
ssize_t size_len = std::max(size.length() + 1,
|
|
|
|
EntryBaseConstants::total_len
|
|
|
|
- name.length() - drop_len - 1);
|
|
|
|
|
|
|
|
if (pruned.length()) {
|
|
|
|
return android::base::StringPrintf("%s%*s%*s\n", name.c_str(),
|
|
|
|
(int)size_len, size.c_str(),
|
|
|
|
(int)drop_len, pruned.c_str());
|
|
|
|
} else {
|
|
|
|
return android::base::StringPrintf("%s%*s\n", name.c_str(),
|
|
|
|
(int)size_len, size.c_str());
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 23:24:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EntryBaseDropped : public EntryBase {
|
|
|
|
size_t dropped;
|
|
|
|
|
|
|
|
EntryBaseDropped():dropped(0) { }
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBaseDropped(LogBufferElement *element):
|
|
|
|
EntryBase(element),
|
|
|
|
dropped(element->getDropped()){
|
|
|
|
}
|
2015-04-13 23:24:45 +02:00
|
|
|
|
2015-03-16 20:04:09 +01:00
|
|
|
size_t getDropped() const { return dropped; }
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(LogBufferElement *element) {
|
|
|
|
dropped += element->getDropped();
|
|
|
|
EntryBase::add(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
inline bool subtract(LogBufferElement *element) {
|
|
|
|
dropped -= element->getDropped();
|
|
|
|
return EntryBase::subtract(element) && !dropped;
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void drop(LogBufferElement *element) {
|
2015-04-13 23:24:45 +02:00
|
|
|
dropped += 1;
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBase::subtract(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UidEntry : public EntryBaseDropped {
|
|
|
|
const uid_t uid;
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
UidEntry(LogBufferElement *element):
|
|
|
|
EntryBaseDropped(element),
|
|
|
|
uid(element->getUid()) {
|
|
|
|
}
|
2015-04-13 23:24:45 +02:00
|
|
|
|
|
|
|
inline const uid_t&getKey() const { return uid; }
|
2015-08-22 01:44:30 +02:00
|
|
|
inline const uid_t&getUid() const { return uid; }
|
|
|
|
|
|
|
|
std::string formatHeader(const std::string &name, log_id_t id) const;
|
|
|
|
std::string format(const LogStatistics &stat, log_id_t id) const;
|
2014-02-06 23:48:50 +01:00
|
|
|
};
|
|
|
|
|
2015-04-13 23:24:45 +02:00
|
|
|
namespace android {
|
|
|
|
uid_t pidToUid(pid_t pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PidEntry : public EntryBaseDropped {
|
2015-03-16 16:26:05 +01:00
|
|
|
const pid_t pid;
|
|
|
|
uid_t uid;
|
|
|
|
char *name;
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
PidEntry(pid_t pid):
|
|
|
|
EntryBaseDropped(),
|
|
|
|
pid(pid),
|
|
|
|
uid(android::pidToUid(pid)),
|
|
|
|
name(android::pidToName(pid)) {
|
|
|
|
}
|
|
|
|
PidEntry(LogBufferElement *element):
|
|
|
|
EntryBaseDropped(element),
|
|
|
|
pid(element->getPid()),
|
|
|
|
uid(element->getUid()),
|
|
|
|
name(android::pidToName(pid)) {
|
|
|
|
}
|
|
|
|
PidEntry(const PidEntry &element):
|
|
|
|
EntryBaseDropped(element),
|
|
|
|
pid(element.pid),
|
|
|
|
uid(element.uid),
|
|
|
|
name(element.name ? strdup(element.name) : NULL) {
|
|
|
|
}
|
2015-03-16 16:26:05 +01:00
|
|
|
~PidEntry() { free(name); }
|
|
|
|
|
|
|
|
const pid_t&getKey() const { return pid; }
|
|
|
|
const uid_t&getUid() const { return uid; }
|
|
|
|
const char*getName() const { return name; }
|
2015-04-13 23:24:45 +02:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(pid_t newPid) {
|
2015-10-02 18:22:52 +02:00
|
|
|
if (name && !fast<strncmp>(name, "zygote", 6)) {
|
2015-04-20 19:27:38 +02:00
|
|
|
free(name);
|
|
|
|
name = NULL;
|
|
|
|
}
|
2015-04-13 23:24:45 +02:00
|
|
|
if (!name) {
|
2015-08-22 01:44:30 +02:00
|
|
|
name = android::pidToName(newPid);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(LogBufferElement *element) {
|
|
|
|
uid_t incomingUid = element->getUid();
|
|
|
|
if (getUid() != incomingUid) {
|
|
|
|
uid = incomingUid;
|
2015-04-13 23:24:45 +02:00
|
|
|
free(name);
|
2015-08-22 01:44:30 +02:00
|
|
|
name = android::pidToName(element->getPid());
|
2015-04-13 23:24:45 +02:00
|
|
|
} else {
|
2015-08-22 01:44:30 +02:00
|
|
|
add(element->getPid());
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBaseDropped::add(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
|
|
|
|
std::string formatHeader(const std::string &name, log_id_t id) const;
|
|
|
|
std::string format(const LogStatistics &stat, log_id_t id) const;
|
2015-04-13 23:24:45 +02:00
|
|
|
};
|
|
|
|
|
2015-04-20 22:35:15 +02:00
|
|
|
struct TidEntry : public EntryBaseDropped {
|
|
|
|
const pid_t tid;
|
|
|
|
uid_t uid;
|
|
|
|
char *name;
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
TidEntry(pid_t tid):
|
|
|
|
EntryBaseDropped(),
|
|
|
|
tid(tid),
|
|
|
|
uid(android::pidToUid(tid)),
|
|
|
|
name(android::tidToName(tid)) {
|
|
|
|
}
|
|
|
|
TidEntry(LogBufferElement *element):
|
|
|
|
EntryBaseDropped(element),
|
|
|
|
tid(element->getTid()),
|
|
|
|
uid(element->getUid()),
|
|
|
|
name(android::tidToName(tid)) {
|
|
|
|
}
|
|
|
|
TidEntry(const TidEntry &element):
|
|
|
|
EntryBaseDropped(element),
|
|
|
|
tid(element.tid),
|
|
|
|
uid(element.uid),
|
|
|
|
name(element.name ? strdup(element.name) : NULL) {
|
|
|
|
}
|
2015-04-20 22:35:15 +02:00
|
|
|
~TidEntry() { free(name); }
|
|
|
|
|
|
|
|
const pid_t&getKey() const { return tid; }
|
|
|
|
const uid_t&getUid() const { return uid; }
|
|
|
|
const char*getName() const { return name; }
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(pid_t incomingTid) {
|
2015-10-02 18:22:52 +02:00
|
|
|
if (name && !fast<strncmp>(name, "zygote", 6)) {
|
2015-04-20 22:35:15 +02:00
|
|
|
free(name);
|
|
|
|
name = NULL;
|
|
|
|
}
|
|
|
|
if (!name) {
|
2015-08-22 01:44:30 +02:00
|
|
|
name = android::tidToName(incomingTid);
|
2015-04-20 22:35:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(LogBufferElement *element) {
|
|
|
|
uid_t incomingUid = element->getUid();
|
|
|
|
if (getUid() != incomingUid) {
|
|
|
|
uid = incomingUid;
|
2015-04-20 22:35:15 +02:00
|
|
|
free(name);
|
2015-08-22 01:44:30 +02:00
|
|
|
name = android::tidToName(element->getTid());
|
2015-04-20 22:35:15 +02:00
|
|
|
} else {
|
2015-08-22 01:44:30 +02:00
|
|
|
add(element->getTid());
|
2015-04-20 22:35:15 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBaseDropped::add(element);
|
2015-04-20 22:35:15 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
|
|
|
|
std::string formatHeader(const std::string &name, log_id_t id) const;
|
|
|
|
std::string format(const LogStatistics &stat, log_id_t id) const;
|
2015-04-20 22:35:15 +02:00
|
|
|
};
|
|
|
|
|
2015-04-13 23:24:45 +02:00
|
|
|
struct TagEntry : public EntryBase {
|
|
|
|
const uint32_t tag;
|
|
|
|
uid_t uid;
|
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
TagEntry(LogBufferElement *element):
|
|
|
|
EntryBase(element),
|
|
|
|
tag(element->getTag()),
|
|
|
|
uid(element->getUid()) {
|
|
|
|
}
|
2015-04-13 23:24:45 +02:00
|
|
|
|
|
|
|
const uint32_t&getKey() const { return tag; }
|
|
|
|
const uid_t&getUid() const { return uid; }
|
|
|
|
const char*getName() const { return android::tagToName(tag); }
|
2015-04-13 23:24:45 +02:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
inline void add(LogBufferElement *element) {
|
|
|
|
uid_t incomingUid = element->getUid();
|
|
|
|
if (uid != incomingUid) {
|
2015-04-13 23:24:45 +02:00
|
|
|
uid = -1;
|
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
EntryBase::add(element);
|
2015-04-13 23:24:45 +02:00
|
|
|
}
|
2015-08-22 01:44:30 +02:00
|
|
|
|
|
|
|
std::string formatHeader(const std::string &name, log_id_t id) const;
|
|
|
|
std::string format(const LogStatistics &stat, log_id_t id) const;
|
2015-03-16 16:26:05 +01:00
|
|
|
};
|
|
|
|
|
2014-02-06 23:48:50 +01:00
|
|
|
// Log Statistics
|
|
|
|
class LogStatistics {
|
2015-08-24 20:08:00 +02:00
|
|
|
friend UidEntry;
|
|
|
|
|
2014-02-06 23:48:50 +01:00
|
|
|
size_t mSizes[LOG_ID_MAX];
|
|
|
|
size_t mElements[LOG_ID_MAX];
|
2015-09-30 16:40:09 +02:00
|
|
|
size_t mDroppedElements[LOG_ID_MAX];
|
2015-03-10 21:51:35 +01:00
|
|
|
size_t mSizesTotal[LOG_ID_MAX];
|
|
|
|
size_t mElementsTotal[LOG_ID_MAX];
|
2015-03-16 16:26:05 +01:00
|
|
|
bool enable;
|
2014-02-06 23:48:50 +01:00
|
|
|
|
2015-03-10 21:51:35 +01:00
|
|
|
// uid to size list
|
2015-03-16 16:26:05 +01:00
|
|
|
typedef LogHashtable<uid_t, UidEntry> uidTable_t;
|
2015-03-10 21:51:35 +01:00
|
|
|
uidTable_t uidTable[LOG_ID_MAX];
|
2014-02-20 02:18:31 +01:00
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
// pid to uid list
|
|
|
|
typedef LogHashtable<pid_t, PidEntry> pidTable_t;
|
|
|
|
pidTable_t pidTable;
|
|
|
|
|
2015-04-20 22:35:15 +02:00
|
|
|
// tid to uid list
|
|
|
|
typedef LogHashtable<pid_t, TidEntry> tidTable_t;
|
|
|
|
tidTable_t tidTable;
|
|
|
|
|
2015-04-13 23:24:45 +02:00
|
|
|
// tag list
|
|
|
|
typedef LogHashtable<uint32_t, TagEntry> tagTable_t;
|
|
|
|
tagTable_t tagTable;
|
|
|
|
|
2014-02-06 23:48:50 +01:00
|
|
|
public:
|
|
|
|
LogStatistics();
|
|
|
|
|
2015-03-16 16:26:05 +01:00
|
|
|
void enableStatistics() { enable = true; }
|
2014-02-06 23:48:50 +01:00
|
|
|
|
2015-03-10 21:51:35 +01:00
|
|
|
void add(LogBufferElement *entry);
|
|
|
|
void subtract(LogBufferElement *entry);
|
2015-03-16 20:04:09 +01:00
|
|
|
// entry->setDropped(1) must follow this call
|
|
|
|
void drop(LogBufferElement *entry);
|
2015-09-30 16:40:09 +02:00
|
|
|
// Correct for coalescing two entries referencing dropped content
|
2015-09-30 16:40:09 +02:00
|
|
|
void erase(LogBufferElement *element) {
|
|
|
|
log_id_t log_id = element->getLogId();
|
|
|
|
--mElements[log_id];
|
|
|
|
--mDroppedElements[log_id];
|
|
|
|
}
|
2014-02-20 02:18:31 +01:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
std::unique_ptr<const UidEntry *[]> sort(size_t len, log_id id) {
|
|
|
|
return uidTable[id].sort(len);
|
|
|
|
}
|
2014-02-06 23:48:50 +01:00
|
|
|
|
|
|
|
// fast track current value by id only
|
|
|
|
size_t sizes(log_id_t id) const { return mSizes[id]; }
|
|
|
|
size_t elements(log_id_t id) const { return mElements[id]; }
|
2015-09-30 16:40:09 +02:00
|
|
|
size_t realElements(log_id_t id) const {
|
|
|
|
return mElements[id] - mDroppedElements[id];
|
|
|
|
}
|
2015-03-10 21:51:35 +01:00
|
|
|
size_t sizesTotal(log_id_t id) const { return mSizesTotal[id]; }
|
|
|
|
size_t elementsTotal(log_id_t id) const { return mElementsTotal[id]; }
|
2014-02-06 23:48:50 +01:00
|
|
|
|
2015-08-22 01:44:30 +02:00
|
|
|
std::string format(uid_t uid, unsigned int logMask) const;
|
2014-04-07 16:05:40 +02:00
|
|
|
|
2015-06-25 01:22:54 +02:00
|
|
|
// helper (must be locked directly or implicitly by mLogElementsLock)
|
2015-08-22 01:44:30 +02:00
|
|
|
const char *pidToName(pid_t pid) const;
|
2014-04-07 16:15:33 +02:00
|
|
|
uid_t pidToUid(pid_t pid);
|
2015-08-22 01:44:30 +02:00
|
|
|
const char *uidToName(uid_t uid) const;
|
2014-02-06 23:48:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _LOGD_LOG_STATISTICS_H__
|