Commit 7acf6d22 authored by Christopher Winter's avatar Christopher Winter
Browse files

Bug 1604914 - Make ShouldProfileThread more efficient r=gerald

When starting the profiler, also make a copy of the filter strings
converted to lower-case. This allows caseless comparisons to be made
against thread names without repeatedly converting the filters to
lower-case for each thread.

Differential Revision: https://phabricator.services.mozilla.com/D123302
parent f8480d1a
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -650,32 +650,32 @@ class ActivePS {
        mWasSamplingPaused(false)
#endif
  {
    // Deep copy aFilters.
    // Deep copy and lower-case aFilters.
    MOZ_ALWAYS_TRUE(mFilters.resize(aFilterCount));
    MOZ_ALWAYS_TRUE(mFiltersLowered.resize(aFilterCount));
    for (uint32_t i = 0; i < aFilterCount; ++i) {
      mFilters[i] = aFilters[i];
      mFiltersLowered[i].reserve(mFilters[i].size());
      std::transform(mFilters[i].cbegin(), mFilters[i].cend(),
                     std::back_inserter(mFiltersLowered[i]), ::tolower);
    }
  }

  ~ActivePS() { CorePS::CoreBuffer().ResetChunkManager(); }

  bool ThreadSelected(const char* aThreadName) {
    if (mFilters.empty()) {
    if (mFiltersLowered.empty()) {
      return true;
    }

    std::string name = aThreadName;
    std::transform(name.begin(), name.end(), name.begin(), ::tolower);

    for (uint32_t i = 0; i < mFilters.length(); ++i) {
      std::string filter = mFilters[i];

    for (const auto& filter : mFiltersLowered) {
      if (filter == "*") {
        return true;
      }

      std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower);

      // Crude, non UTF-8 compatible, case insensitive substring search
      if (name.find(filter) != std::string::npos) {
        return true;
@@ -778,6 +778,7 @@ class ActivePS {
#undef PS_GET_FEATURE

  PS_GET(const Vector<std::string>&, Filters)
  PS_GET(const Vector<std::string>&, FiltersLowered)

  static void FulfillChunkRequests(PSLockRef) {
    MOZ_ASSERT(sInstance);
@@ -1032,6 +1033,7 @@ class ActivePS {

  // Substrings of names of threads we want to profile.
  Vector<std::string> mFilters;
  Vector<std::string> mFiltersLowered;

  // The chunk manager used by `mProfileBuffer` below.
  ProfileBufferChunkManagerWithLocalLimit mProfileBufferChunkManager;
+9 −7
Original line number Diff line number Diff line
@@ -698,10 +698,14 @@ class ActivePS {
        mWasSamplingPaused(false)
#endif
  {
    // Deep copy aFilters.
    // Deep copy and lower-case aFilters.
    MOZ_ALWAYS_TRUE(mFilters.resize(aFilterCount));
    MOZ_ALWAYS_TRUE(mFiltersLowered.resize(aFilterCount));
    for (uint32_t i = 0; i < aFilterCount; ++i) {
      mFilters[i] = aFilters[i];
      mFiltersLowered[i].reserve(mFilters[i].size());
      std::transform(mFilters[i].cbegin(), mFilters[i].cend(),
                     std::back_inserter(mFiltersLowered[i]), ::tolower);
    }

#if !defined(RELEASE_OR_BETA)
@@ -746,22 +750,18 @@ class ActivePS {
  }

  bool ThreadSelected(const char* aThreadName) {
    if (mFilters.empty()) {
    if (mFiltersLowered.empty()) {
      return true;
    }

    std::string name = aThreadName;
    std::transform(name.begin(), name.end(), name.begin(), ::tolower);

    for (uint32_t i = 0; i < mFilters.length(); ++i) {
      std::string filter = mFilters[i];

    for (const auto& filter : mFiltersLowered) {
      if (filter == "*") {
        return true;
      }

      std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower);

      // Crude, non UTF-8 compatible, case insensitive substring search
      if (name.find(filter) != std::string::npos) {
        return true;
@@ -940,6 +940,7 @@ class ActivePS {
  }

  PS_GET(const Vector<std::string>&, Filters)
  PS_GET(const Vector<std::string>&, FiltersLowered)

  // Not using PS_GET, because only the "Controlled" interface of
  // `mProfileBufferChunkManager` should be exposed here.
@@ -1259,6 +1260,7 @@ class ActivePS {

  // Substrings of names of threads we want to profile.
  Vector<std::string> mFilters;
  Vector<std::string> mFiltersLowered;

  // ID of the active browser screen's active tab.
  // It's being used to determine the profiled tab. It's "0" if we failed to