• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_PRIORITYDUMPER_H
18 #define ANDROID_UTILS_PRIORITYDUMPER_H
19 
20 #include <utils/Errors.h>
21 #include <utils/String16.h>
22 #include <utils/Vector.h>
23 
24 namespace android {
25 
26 // Helper class to parse common arguments responsible for splitting dumps into
27 // various priority buckets and changing the output format of the dump.
28 class PriorityDumper {
29 public:
30     static const char16_t PRIORITY_ARG[];
31     static const char16_t PRIORITY_ARG_CRITICAL[];
32     static const char16_t PRIORITY_ARG_HIGH[];
33     static const char16_t PRIORITY_ARG_NORMAL[];
34     static const char16_t PROTO_ARG[];
35 
36     // Parses the argument list searching for --dump_priority with a priority type
37     // (HIGH, CRITICAL or NORMAL) and --proto. Matching arguments are stripped.
38     // If a valid priority type is found, the associated PriorityDumper
39     // method is called otherwise all supported sections are dumped.
40     // If --proto is found, the dumpAsProto flag is set to dump sections in proto
41     // format.
42     status_t priorityDump(int fd, const Vector<String16>& args);
43 
44     // Dumps CRITICAL priority sections.
dumpCritical(int,const Vector<String16> &,bool)45     virtual status_t dumpCritical(int /*fd*/, const Vector<String16>& /*args*/, bool /*asProto*/) {
46         return OK;
47     }
48 
49     // Dumps HIGH priority sections.
dumpHigh(int,const Vector<String16> &,bool)50     virtual status_t dumpHigh(int /*fd*/, const Vector<String16>& /*args*/, bool /*asProto*/) {
51         return OK;
52     }
53 
54     // Dumps normal priority sections.
dumpNormal(int,const Vector<String16> &,bool)55     virtual status_t dumpNormal(int /*fd*/, const Vector<String16>& /*args*/, bool /*asProto*/) {
56         return OK;
57     }
58 
59     // Dumps all sections.
60     // This method is called when priorityDump is called without priority
61     // arguments. By default, it calls all three dump methods.
62     virtual status_t dumpAll(int fd, const Vector<String16>& args, bool asProto);
63     virtual ~PriorityDumper() = default;
64 };
65 
66 } // namespace android
67 
68 #endif // ANDROID_UTILS_PRIORITYDUMPER_H
69