src/testing/loadbench/utility.cc
zx::unowned_profile GetProfile(zx::duration capacity, zx::duration deadline, zx::duration period,
                               std::optional<zx_cpu_set_t> affinity) {
  using Key = std::tuple<zx_duration_t, zx_duration_t, zx_duration_t, std::optional<zx_cpu_set_t>>;
  const Key key{capacity.get(), deadline.get(), period.get(), affinity};

  // Maintains a map of profiles for each previously requested deadline/affinity.
  static std::map<Key, zx::profile> profiles;
  static std::mutex mutex;

  std::lock_guard<std::mutex> guard{mutex};

  // Return the existing handle if it's already in the map.
  auto search = profiles.find(key);
  if (search != profiles.end()) {
    return zx::unowned_profile{search->second.get()};
  }

  auto& provider = GetProfileProvider();

  zx_status_t fidl_status;
  zx::profile profile;
  const auto status = provider.GetDeadlineProfile(capacity.get(), deadline.get(), period.get(),
                                                  "garnet/bin/loadbench", &fidl_status, &profile);
  FXL_CHECK(status == ZX_OK);
  FXL_CHECK(fidl_status == ZX_OK);

  // Add the new profile to the map for later retrieval.
  auto [iter, okay] = profiles.emplace(key, std::move(profile));
  FXL_CHECK(okay);

  return zx::unowned_profile{iter->second.get()};
}
// Returns an unowned handle to a profile for the specified deadline parameters.
// Maintains an internal map of already requested profiles and returns the same
// handle for multiple request for the same deadline parameters.
Returns an unowned handle to a profile for the specified deadline parameters.
Maintains an internal map of already requested profiles and returns the same
handle for multiple request for the same deadline parameters.
Returns an unowned handle to a profile for the specified deadline parameters . Maintains an internal map of already requested profiles and returns the same handle for multiple request for the same deadline parameters .
zx::unowned_profile GetProfile(zx::duration capacity, zx::duration deadline, zx::duration period,
                               std::optional<zx_cpu_set_t> affinity) {
  using Key = std::tuple<zx_duration_t, zx_duration_t, zx_duration_t, std::optional<zx_cpu_set_t>>;
  const Key key{capacity.get(), deadline.get(), period.get(), affinity};
  static std::map<Key, zx::profile> profiles;
  static std::mutex mutex;
  std::lock_guard<std::mutex> guard{mutex};
  auto search = profiles.find(key);
  if (search != profiles.end()) {
    return zx::unowned_profile{search->second.get()};
  }
  auto& provider = GetProfileProvider();
  zx_status_t fidl_status;
  zx::profile profile;
  const auto status = provider.GetDeadlineProfile(capacity.get(), deadline.get(), period.get(),
                                                  "garnet/bin/loadbench", &fidl_status, &profile);
  FXL_CHECK(status == ZX_OK);
  FXL_CHECK(fidl_status == ZX_OK);
  auto [iter, okay] = profiles.emplace(key, std::move(profile));
  FXL_CHECK(okay);
  return zx::unowned_profile{iter->second.get()};
}
zx :: unowned_profile GetProfile ( zx :: duration capacity , zx :: duration deadline , zx :: duration period , std :: optional < zx_cpu_set_t > affinity ) { using Key = std :: tuple < zx_duration_t , zx_duration_t , zx_duration_t , std :: optional < zx_cpu_set_t > > ; const Key key { capacity . get ( ) , deadline . get ( ) , period . get ( ) , affinity } ; static std :: map < Key , zx :: profile > profiles ; static std :: mutex mutex ; std :: lock_guard < std :: mutex > guard { mutex } ; auto search = profiles . find ( key ) ; if ( search != profiles . end ( ) ) { return zx :: unowned_profile { search -> second . get ( ) } ; } auto & provider = GetProfileProvider ( ) ; zx_status_t fidl_status ; zx :: profile profile ; const auto status = provider . GetDeadlineProfile ( capacity . get ( ) , deadline . get ( ) , period . get ( ) , " " , & fidl_status , & profile ) ; FXL_CHECK ( status == ZX_OK ) ; FXL_CHECK ( fidl_status == ZX_OK ) ; auto [ iter , okay ] = profiles . emplace ( key , std :: move ( profile ) ) ; FXL_CHECK ( okay ) ; return zx :: unowned_profile { iter -> second . get ( ) } ; }
Returns an unowned handle to a profile for the specified deadline parameters.
Returns an unowned handle to a profile for the specified deadline parameters .
// Maintains a map of profiles for each previously requested deadline/affinity. // Return the existing handle if it's already in the map. // Add the new profile to the map for later retrieval.