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

Commit ff9cba7e authored by Yurii Zubrytskyi's avatar Yurii Zubrytskyi
Browse files

[nit] Clean up the resource resolution debugging

- Better struct memory layout
- Get rid of unneeded unordered_map

Bug: n/a
Test: builds
Change-Id: I3c7d8d99bff5aa35621b61956a0fd2f5a7a48aa3
parent 831fda61
Loading
Loading
Loading
Loading
+18 −27
Original line number Original line Diff line number Diff line
@@ -632,7 +632,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(


        if (UNLIKELY(logging_enabled)) {
        if (UNLIKELY(logging_enabled)) {
          last_resolution_.steps.push_back(
          last_resolution_.steps.push_back(
              Resolution::Step{Resolution::Step::Type::OVERLAID_INLINE, String8(), result->cookie});
              Resolution::Step{Resolution::Step::Type::OVERLAID_INLINE, result->cookie, String8()});
          if (auto path = apk_assets_[result->cookie]->GetPath()) {
          if (auto path = apk_assets_[result->cookie]->GetPath()) {
            const std::string overlay_path = path->data();
            const std::string overlay_path = path->data();
            if (IsFabricatedOverlay(overlay_path)) {
            if (IsFabricatedOverlay(overlay_path)) {
@@ -682,8 +682,8 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntry(


      if (UNLIKELY(logging_enabled)) {
      if (UNLIKELY(logging_enabled)) {
        last_resolution_.steps.push_back(
        last_resolution_.steps.push_back(
            Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->config.toString(),
            Resolution::Step{Resolution::Step::Type::OVERLAID, overlay_result->cookie,
                             overlay_result->cookie});
                             overlay_result->config.toString()});
        last_resolution_.best_package_name =
        last_resolution_.best_package_name =
            overlay_result->package_name->c_str();
            overlay_result->package_name->c_str();
        overlaid = true;
        overlaid = true;
@@ -769,8 +769,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
      } else {
      } else {
        if (UNLIKELY(logging_enabled)) {
        if (UNLIKELY(logging_enabled)) {
          last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::SKIPPED,
          last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::SKIPPED,
                                                      this_config.toString(),
                                                            cookie, this_config.toString()});
                                                      cookie});
        }
        }
        continue;
        continue;
      }
      }
@@ -786,8 +785,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
      if (!offset.has_value()) {
      if (!offset.has_value()) {
        if (UNLIKELY(logging_enabled)) {
        if (UNLIKELY(logging_enabled)) {
          last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::NO_ENTRY,
          last_resolution_.steps.push_back(Resolution::Step{Resolution::Step::Type::NO_ENTRY,
                                                      this_config.toString(),
                                                            cookie, this_config.toString()});
                                                      cookie});
        }
        }
        continue;
        continue;
      }
      }
@@ -800,8 +798,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(


      if (UNLIKELY(logging_enabled)) {
      if (UNLIKELY(logging_enabled)) {
        last_resolution_.steps.push_back(Resolution::Step{resolution_type,
        last_resolution_.steps.push_back(Resolution::Step{resolution_type,
                                                          this_config.toString(),
                                                          cookie, this_config.toString()});
                                                          cookie});
      }
      }


      // Any configuration will suffice, so break.
      // Any configuration will suffice, so break.
@@ -839,13 +836,7 @@ base::expected<FindEntryResult, NullOrIOError> AssetManager2::FindEntryInternal(
}
}


void AssetManager2::ResetResourceResolution() const {
void AssetManager2::ResetResourceResolution() const {
  last_resolution_.cookie = kInvalidCookie;
  last_resolution_ = Resolution{};
  last_resolution_.resid = 0;
  last_resolution_.steps.clear();
  last_resolution_.type_string_ref = StringPoolRef();
  last_resolution_.entry_string_ref = StringPoolRef();
  last_resolution_.best_config_name.clear();
  last_resolution_.best_package_name.clear();
}
}


void AssetManager2::SetResourceResolutionLoggingEnabled(bool enabled) {
void AssetManager2::SetResourceResolutionLoggingEnabled(bool enabled) {
@@ -885,21 +876,21 @@ std::string AssetManager2::GetLastResourceResolution() const {
                                   configuration_.toString().c_str());
                                   configuration_.toString().c_str());


  for (const Resolution::Step& step : last_resolution_.steps) {
  for (const Resolution::Step& step : last_resolution_.steps) {
    const static std::unordered_map<Resolution::Step::Type, const char*> kStepStrings = {
    constexpr static std::array kStepStrings = {
        {Resolution::Step::Type::INITIAL,         "Found initial"},
        "Found initial",
        {Resolution::Step::Type::BETTER_MATCH,    "Found better"},
        "Found better",
        {Resolution::Step::Type::OVERLAID,        "Overlaid"},
        "Overlaid",
        {Resolution::Step::Type::OVERLAID_INLINE, "Overlaid inline"},
        "Overlaid inline",
        {Resolution::Step::Type::SKIPPED,         "Skipped"},
        "Skipped",
        {Resolution::Step::Type::NO_ENTRY,        "No entry"}
        "No entry"
    };
    };


    const auto prefix = kStepStrings.find(step.type);
    if (step.type < Resolution::Step::Type::INITIAL
    if (prefix == kStepStrings.end()) {
        || step.type > Resolution::Step::Type::NO_ENTRY) {
      continue;
      continue;
    }
    }

    const auto prefix = kStepStrings[int(step.type) - int(Resolution::Step::Type::INITIAL)];
    log_stream << "\n\t" << prefix->second << ": " << apk_assets_[step.cookie]->GetDebugName();
    log_stream << "\n\t" << prefix << ": " << apk_assets_[step.cookie]->GetDebugName();
    if (!step.config_name.isEmpty()) {
    if (!step.config_name.isEmpty()) {
      log_stream << " - " << step.config_name;
      log_stream << " - " << step.config_name;
    }
    }
+2 −2
Original line number Original line Diff line number Diff line
@@ -463,10 +463,10 @@ class AssetManager2 {
      // Marks what kind of override this step was.
      // Marks what kind of override this step was.
      Type type;
      Type type;


      ApkAssetsCookie cookie = kInvalidCookie;

      // Built name of configuration for this step.
      // Built name of configuration for this step.
      String8 config_name;
      String8 config_name;

      ApkAssetsCookie cookie = kInvalidCookie;
    };
    };


    // Last resolved resource ID.
    // Last resolved resource ID.