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

Commit de61a6b4 authored by Yangster-mac's avatar Yangster-mac Committed by android-build-merger
Browse files

Merge "Logd retry throttling." into pi-dev am: 3ed86622

am: 3e871cb7

Change-Id: I33e6de119dda1209523de1fdade8e1a4c5e08da5
parents 17133935 3e871cb7
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
    fprintf(out, "// This file is autogenerated\n");
    fprintf(out, "\n");

    fprintf(out, "#include <mutex>\n");
    fprintf(out, "#include <chrono>\n");
    fprintf(out, "#include <thread>\n");
    fprintf(out, "#include <log/log_event_list.h>\n");
@@ -150,9 +151,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
    fprintf(out, "};\n");
    fprintf(out, "\n");

    fprintf(out,
            "static std::map<int, int> "
            "getAtomUidField() {\n");
    fprintf(out, "static std::map<int, int> getAtomUidField() {\n");
    fprintf(out, "  std::map<int, int> uidField;\n");
    for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
         atom != atoms.decls.end(); atom++) {
@@ -206,6 +205,11 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
            "AtomsInfo::kStateAtomsFieldOptions = "
            "getStateAtomFieldOptions();\n");


    fprintf(out, "int64_t lastRetryTimestampNs = -1;\n");
    fprintf(out, "const int64_t kMinRetryIntervalNs = NS_PER_SEC * 60 * 20; // 20 minutes\n");
    fprintf(out, "static std::mutex mLogdRetryMutex;\n");

    // Print write methods
    fprintf(out, "\n");
    for (set<vector<java_type_t>>::const_iterator signature = atoms.signatures.begin();
@@ -317,7 +321,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
       fprintf(out, "{\n");
       fprintf(out, "  int ret = 0;\n");

       fprintf(out, "  for(int retry = 0; retry < 3; ++retry) {\n");
       fprintf(out, "  for(int retry = 0; retry < 2; ++retry) {\n");
       fprintf(out, "      ret =  try_stats_write(code");

       argIndex = 1;
@@ -340,8 +344,15 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
       }
       fprintf(out, ");\n");
       fprintf(out, "      if (ret >= 0) { return retry; }\n");
       fprintf(out,
               "      std::this_thread::sleep_for(std::chrono::milliseconds(10 + 10 * retry));\n");


       fprintf(out, "      {\n");
       fprintf(out, "          std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n");
       fprintf(out, "          if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= "
                                "kMinRetryIntervalNs) break;\n");
       fprintf(out, "          lastRetryTimestampNs = android::elapsedRealtimeNano();\n");
       fprintf(out, "      }\n");
       fprintf(out, "      std::this_thread::sleep_for(std::chrono::milliseconds(10));\n");
       fprintf(out, "  }\n");
       fprintf(out, "  return ret;\n");
       fprintf(out, "}\n");
@@ -408,7 +419,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
       fprintf(out, "{\n");

       fprintf(out, "  int ret = 0;\n");
       fprintf(out, "  for(int retry = 0; retry < 3; ++retry) {\n");
       fprintf(out, "  for(int retry = 0; retry < 2; ++retry) {\n");
       fprintf(out, "      ret =  try_stats_write_non_chained(code");

       argIndex = 1;
@@ -419,8 +430,15 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
       }
       fprintf(out, ");\n");
       fprintf(out, "      if (ret >= 0) { return retry; }\n");
       fprintf(out,
               "      std::this_thread::sleep_for(std::chrono::milliseconds(10 + 10 * retry));\n");

       fprintf(out, "      {\n");
       fprintf(out, "          std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n");
       fprintf(out, "          if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= "
                                "kMinRetryIntervalNs) break;\n");
       fprintf(out, "          lastRetryTimestampNs = android::elapsedRealtimeNano();\n");
       fprintf(out, "      }\n");

       fprintf(out, "      std::this_thread::sleep_for(std::chrono::milliseconds(10));\n");
       fprintf(out, "  }\n");
       fprintf(out, "  return ret;\n");
       fprintf(out, "}\n");