Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 208bef3a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added PriorityDump helper util"

parents e61c9b10 33fd3be6
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
// Copyright (C) 2017 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.

//
// Static library used in testing and executables
//
cc_library_static {
    name: "libserviceutils",

    cflags: [
        "-Wall",
        "-Wno-unused-parameter",
        "-Werror",
    ],

    srcs: [
        "PriorityDumper.cpp",
    ],

    clang: true,
    export_include_dirs: ["include"],
}

subdirs = ["tests"]
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#include "include/PriorityDumper.h"

namespace android {

static void getStrippedArgs(Vector<String16>& dest, const Vector<String16>& source,
                            std::size_t numArgsToStrip) {
    for (auto it = source.begin() + numArgsToStrip; it != source.end(); it++) {
        dest.add(*it);
    }
}

void priorityDump(PriorityDumper& dumper, int fd, const Vector<String16>& args) {
    if (args.size() >= 2 && args[0] == PRIORITY_ARG) {
        String16 priority = args[1];
        Vector<String16> strippedArgs;
        getStrippedArgs(strippedArgs, args, 2);
        if (priority == PRIORITY_ARG_CRITICAL) {
            dumper.dumpCritical(fd, strippedArgs);
        } else if (priority == PRIORITY_ARG_HIGH) {
            dumper.dumpHigh(fd, strippedArgs);
        } else if (priority == PRIORITY_ARG_NORMAL) {
            dumper.dumpNormal(fd, strippedArgs);
        } else {
            dumper.dump(fd, args);
        }
    } else {
        dumper.dump(fd, args);
    }
}
} // namespace android
 No newline at end of file
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 ANDROID_UTILS_PRIORITYDUMP_H
#define ANDROID_UTILS_PRIORITYDUMP_H

#include <utils/String16.h>
#include <utils/Vector.h>

namespace android {

constexpr const char16_t PRIORITY_ARG[] = u"--dump-priority";
constexpr const char16_t PRIORITY_ARG_CRITICAL[] = u"CRITICAL";
constexpr const char16_t PRIORITY_ARG_HIGH[] = u"HIGH";
constexpr const char16_t PRIORITY_ARG_NORMAL[] = u"NORMAL";

// Helper class to split dumps into various priority buckets.
class PriorityDumper {
public:
    // Dumps CRITICAL priority sections.
    virtual void dumpCritical(int fd, const Vector<String16>& args) {}

    // Dumps HIGH priority sections.
    virtual void dumpHigh(int fd, const Vector<String16>& args) {}

    // Dumps normal priority sections.
    virtual void dumpNormal(int fd, const Vector<String16>& args) {}

    // Dumps all sections.
    // This method is called when priorityDump is called without priority
    // arguments. By default, it calls all three dump methods.
    virtual void dump(int fd, const Vector<String16>& args) {
        dumpCritical(fd, args);
        dumpHigh(fd, args);
        dumpNormal(fd, args);
    }
    virtual ~PriorityDumper() = default;
};

// Parses the argument list checking if the first argument is --dump_priority and
// the second argument is the priority type (HIGH, CRITICAL or NORMAL). If the
// arguments are found, they are stripped and the appropriate PriorityDumper
// method is called.
// If --dump_priority argument is not passed, all supported sections are dumped.
void priorityDump(PriorityDumper& dumper, int fd, const Vector<String16>& args);

}; // namespace android

#endif // ANDROID_UTILS_PRIORITYDUMP_H
+32 −0
Original line number Diff line number Diff line
// Copyright (C) 2017 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.

// Build unit tests.

cc_test {
    name: "prioritydumper_test",
    test_suites: ["device-tests"],
    srcs: [ "PriorityDumper_test.cpp"],
    shared_libs: [
        "libutils",
    ],
    cflags: [
        "-Wno-unused-parameter",
    ],
    static_libs = [
        "libgmock",
        "libserviceutils"
    ],
    clang: true,
}
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 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.
-->
<configuration description="Config for prioritydumper_test">
  <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
    <option name="cleanup" value="true" />
    <option name="push" value="prioritydumper_test->/data/local/tmp/prioritydumper_test" />
  </target_preparer>
  <option name="test-suite-tag" value="apct" />
  <test class="com.android.tradefed.testtype.GTest" >
    <option name="native-test-device-path" value="/data/local/tmp" />
    <option name="module-name" value="prioritydumper_test" />
  </test>
</configuration>
 No newline at end of file
Loading