Vishnu Nair | deb36f2 | 2017-10-05 20:35:18 -0700 | [diff] [blame^] | 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 | constexpr const char16_t PRIORITY_ARG[] = u"--dump-priority"; |
| 27 | constexpr const char16_t PRIORITY_ARG_CRITICAL[] = u"CRITICAL"; |
| 28 | constexpr const char16_t PRIORITY_ARG_HIGH[] = u"HIGH"; |
| 29 | constexpr const char16_t PRIORITY_ARG_NORMAL[] = u"NORMAL"; |
| 30 | |
| 31 | // Helper class to split dumps into various priority buckets. |
| 32 | class PriorityDumper { |
| 33 | public: |
| 34 | // Parses the argument list checking if the first argument is --dump_priority and |
| 35 | // the second argument is the priority type (HIGH, CRITICAL or NORMAL). If the |
| 36 | // arguments are found, they are stripped and the appropriate PriorityDumper |
| 37 | // method is called. |
| 38 | // If --dump_priority argument is not passed, all supported sections are dumped. |
| 39 | status_t priorityDump(int fd, const Vector<String16>& args); |
| 40 | |
| 41 | // Dumps CRITICAL priority sections. |
| 42 | virtual status_t dumpCritical(int /*fd*/, const Vector<String16>& /*args*/) { return OK; } |
| 43 | |
| 44 | // Dumps HIGH priority sections. |
| 45 | virtual status_t dumpHigh(int /*fd*/, const Vector<String16>& /*args*/) { return OK; } |
| 46 | |
| 47 | // Dumps normal priority sections. |
| 48 | virtual status_t dumpNormal(int /*fd*/, const Vector<String16>& /*args*/) { return OK; } |
| 49 | |
| 50 | // Dumps all sections. |
| 51 | // This method is called when priorityDump is called without priority |
| 52 | // arguments. By default, it calls all three dump methods. |
| 53 | virtual status_t dumpAll(int fd, const Vector<String16>& args); |
| 54 | virtual ~PriorityDumper() = default; |
| 55 | }; |
| 56 | |
| 57 | } // namespace android |
| 58 | |
| 59 | #endif // ANDROID_UTILS_PRIORITYDUMPER_H |