blob: 23e900d90e1fc3826d228ba0eecc6776f27d5d8b [file] [log] [blame]
Vishnu Nair33fd3be2017-09-27 11:06:37 -07001/*
2 * Copyright (C) 2017 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 ANDROID_UTILS_PRIORITYDUMP_H
18#define ANDROID_UTILS_PRIORITYDUMP_H
19
20#include <utils/String16.h>
21#include <utils/Vector.h>
22
23namespace android {
24
25constexpr const char16_t PRIORITY_ARG[] = u"--dump-priority";
26constexpr const char16_t PRIORITY_ARG_CRITICAL[] = u"CRITICAL";
27constexpr const char16_t PRIORITY_ARG_HIGH[] = u"HIGH";
28constexpr const char16_t PRIORITY_ARG_NORMAL[] = u"NORMAL";
29
30// Helper class to split dumps into various priority buckets.
31class PriorityDumper {
32public:
33 // Dumps CRITICAL priority sections.
34 virtual void dumpCritical(int fd, const Vector<String16>& args) {}
35
36 // Dumps HIGH priority sections.
37 virtual void dumpHigh(int fd, const Vector<String16>& args) {}
38
39 // Dumps normal priority sections.
40 virtual void dumpNormal(int fd, const Vector<String16>& args) {}
41
42 // Dumps all sections.
43 // This method is called when priorityDump is called without priority
44 // arguments. By default, it calls all three dump methods.
45 virtual void dump(int fd, const Vector<String16>& args) {
46 dumpCritical(fd, args);
47 dumpHigh(fd, args);
48 dumpNormal(fd, args);
49 }
50 virtual ~PriorityDumper() = default;
51};
52
53// Parses the argument list checking if the first argument is --dump_priority and
54// the second argument is the priority type (HIGH, CRITICAL or NORMAL). If the
55// arguments are found, they are stripped and the appropriate PriorityDumper
56// method is called.
57// If --dump_priority argument is not passed, all supported sections are dumped.
58void priorityDump(PriorityDumper& dumper, int fd, const Vector<String16>& args);
59
60}; // namespace android
61
62#endif // ANDROID_UTILS_PRIORITYDUMP_H