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

Commit b67268b3 authored by Naveen Kumar's avatar Naveen Kumar
Browse files

Merge N-MR1 to remote branch.

Change-Id: I9e2c8443ec5e9ac7b265ce55151769b34c5edc76
parents a754d878 dc8e0de6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ static const TracingCategory k_categories[] = {
    { "pm",         "Package Manager",  ATRACE_TAG_PACKAGE_MANAGER, { } },
    { "ss",         "System Server",    ATRACE_TAG_SYSTEM_SERVER, { } },
    { "database",   "Database",         ATRACE_TAG_DATABASE, { } },
    { "network",    "Network",          ATRACE_TAG_NETWORK, { } },
    { k_coreServiceCategory, "Core services", 0, { } },
    { "sched",      "CPU Scheduling",   0, {
        { REQ,      "/sys/kernel/debug/tracing/events/sched/sched_switch/enable" },
+1 −1
Original line number Diff line number Diff line
## Permissions to allow system-wide tracing to the kernel trace buffer.
##
on boot
on fs

# Allow writing to the kernel trace log.
    chmod 0222 /sys/kernel/debug/tracing/trace_marker
+13 −0
Original line number Diff line number Diff line
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false

AccessModifierOffset: -2
ColumnLimit: 100
CommentPragmas: NOLINT:.*
DerivePointerAlignment: false
IndentWidth: 4
PointerAlignment: Left
TabWidth: 4
UseTab: Never
PenaltyExcessCharacter: 32
+34 −3
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)

# bugreportz
# ==========

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= bugreportz.cpp
LOCAL_SRC_FILES:= \
   bugreportz.cpp \
   main.cpp \

LOCAL_MODULE:= bugreportz

LOCAL_CFLAGS := -Wall
LOCAL_CFLAGS := -Werror -Wall

LOCAL_SHARED_LIBRARIES := libcutils
LOCAL_SHARED_LIBRARIES := \
    libbase \
    libcutils \

include $(BUILD_EXECUTABLE)

# bugreportz_test
# ===============

include $(CLEAR_VARS)

LOCAL_MODULE := bugreportz_test
LOCAL_MODULE_TAGS := tests

LOCAL_CFLAGS := -Werror -Wall

LOCAL_SRC_FILES := \
    bugreportz.cpp \
    bugreportz_test.cpp \

LOCAL_STATIC_LIBRARIES := \
    libgmock \

LOCAL_SHARED_LIBRARIES := \
    libbase \
    libutils \

include $(BUILD_NATIVE_TEST)
+30 −84
Original line number Diff line number Diff line
@@ -15,89 +15,38 @@
 */

#include <errno.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <cutils/properties.h>
#include <cutils/sockets.h>
#include <string>

static constexpr char VERSION[] = "1.0";
#include <android-base/file.h>
#include <android-base/strings.h>

static void show_usage() {
  fprintf(stderr,
          "usage: bugreportz [-h | -v]\n"
          "  -h: to display this help message\n"
          "  -v: to display the version\n"
          "  or no arguments to generate a zipped bugreport\n");
}

static void show_version() {
  fprintf(stderr, "%s\n", VERSION);
}

int main(int argc, char *argv[]) {

    if (argc > 1) {
        /* parse arguments */
        int c;
        while ((c = getopt(argc, argv, "vh")) != -1) {
            switch (c) {
                case 'h':
                    show_usage();
                    return EXIT_SUCCESS;
                case 'v':
                    show_version();
                    return EXIT_SUCCESS;
                default:
                    show_usage();
                    return EXIT_FAILURE;
            }
        }
        // passed an argument not starting with -
        if (optind > 1 || argv[optind] != nullptr) {
            show_usage();
            return EXIT_FAILURE;
        }
    }
#include "bugreportz.h"

    // TODO: code below was copy-and-pasted from bugreport.cpp (except by the timeout value);
    // should be reused instead.
static constexpr char BEGIN_PREFIX[] = "BEGIN:";
static constexpr char PROGRESS_PREFIX[] = "PROGRESS:";

    // Start the dumpstatez service.
    property_set("ctl.start", "dumpstatez");
static void write_line(const std::string& line, bool show_progress) {
    if (line.empty()) return;

    // Socket will not be available until service starts.
    int s;
    for (int i = 0; i < 20; i++) {
        s = socket_local_client("dumpstate", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM);
        if (s >= 0)
            break;
        // Try again in 1 second.
        sleep(1);
    }
    // When not invoked with the -p option, it must skip BEGIN and PROGRESS lines otherwise it
    // will break adb (which is expecting either OK or FAIL).
    if (!show_progress && (android::base::StartsWith(line, PROGRESS_PREFIX) ||
                           android::base::StartsWith(line, BEGIN_PREFIX)))
        return;

    if (s == -1) {
        printf("FAIL:Failed to connect to dumpstatez service: %s\n", strerror(errno));
        return EXIT_SUCCESS;
    }

    // Set a timeout so that if nothing is read in 10 minutes, we'll stop
    // reading and quit. No timeout in dumpstate is longer than 60 seconds,
    // so this gives lots of leeway in case of unforeseen time outs.
    struct timeval tv;
    tv.tv_sec = 10 * 60;
    tv.tv_usec = 0;
    if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
        fprintf(stderr, "WARNING: Cannot set socket timeout: %s\n", strerror(errno));
    android::base::WriteStringToFd(line, STDOUT_FILENO);
}

int bugreportz(int s, bool show_progress) {
    std::string line;
    while (1) {
        char buffer[65536];
        ssize_t bytes_read = TEMP_FAILURE_RETRY(
                read(s, buffer, sizeof(buffer)));
        ssize_t bytes_read = TEMP_FAILURE_RETRY(read(s, buffer, sizeof(buffer)));
        if (bytes_read == 0) {
            break;
        } else if (bytes_read == -1) {
@@ -109,21 +58,18 @@ int main(int argc, char *argv[]) {
            break;
        }

        ssize_t bytes_to_send = bytes_read;
        ssize_t bytes_written;
        do {
            bytes_written = TEMP_FAILURE_RETRY(
                    write(STDOUT_FILENO, buffer + bytes_read - bytes_to_send,
                            bytes_to_send));
            if (bytes_written == -1) {
                fprintf(stderr,
                        "Failed to write data to stdout: read %zd, trying to send %zd (%s)\n",
                        bytes_read, bytes_to_send, strerror(errno));
                break;
        // Writes line by line.
        for (int i = 0; i < bytes_read; i++) {
            char c = buffer[i];
            line.append(1, c);
            if (c == '\n') {
                write_line(line, show_progress);
                line.clear();
            }
        }
            bytes_to_send -= bytes_written;
        } while (bytes_written != 0 && bytes_to_send > 0);
    }
    // Process final line, in case it didn't finish with newline
    write_line(line, show_progress);

    if (close(s) == -1) {
        fprintf(stderr, "WARNING: error closing socket: %s\n", strerror(errno));
Loading