| Index: third_party/grpc/test/cpp/qps/limit_cores.cc
|
| diff --git a/third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.cpp b/third_party/grpc/test/cpp/qps/limit_cores.cc
|
| similarity index 58%
|
| copy from third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.cpp
|
| copy to third_party/grpc/test/cpp/qps/limit_cores.cc
|
| index 09fbdb944f6ecabccadf4f25f7927450297e1ce3..fad9a323afd191691c58f8b0786b05720857d89c 100644
|
| --- a/third_party/WebKit/Source/modules/quota/StorageQuotaCallbacksImpl.cpp
|
| +++ b/third_party/grpc/test/cpp/qps/limit_cores.cc
|
| @@ -1,5 +1,7 @@
|
| /*
|
| - * Copyright (C) 2011 Google Inc. All rights reserved.
|
| + *
|
| + * Copyright 2016, Google Inc.
|
| + * All rights reserved.
|
| *
|
| * Redistribution and use in source and binary forms, with or without
|
| * modification, are permitted provided that the following conditions are
|
| @@ -26,43 +28,52 @@
|
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + *
|
| */
|
|
|
| -#include "modules/quota/StorageQuotaCallbacksImpl.h"
|
| -
|
| -#include "core/dom/DOMError.h"
|
| -#include "modules/quota/StorageInfo.h"
|
| +#include "test/cpp/qps/limit_cores.h"
|
|
|
| -namespace blink {
|
| +#include <grpc/support/cpu.h>
|
| +#include <grpc/support/log.h>
|
| +#include <grpc/support/port_platform.h>
|
|
|
| -StorageQuotaCallbacksImpl::StorageQuotaCallbacksImpl(ScriptPromiseResolver* resolver)
|
| - : m_resolver(resolver)
|
| -{
|
| -}
|
| +namespace grpc {
|
| +namespace testing {
|
|
|
| -StorageQuotaCallbacksImpl::~StorageQuotaCallbacksImpl()
|
| -{
|
| -}
|
| +#ifdef GPR_CPU_LINUX
|
| +#ifndef _GNU_SOURCE
|
| +#define _GNU_SOURCE
|
| +#endif
|
| +#include <sched.h>
|
| +int LimitCores(const int* cores, int cores_size) {
|
| + const int num_cores = gpr_cpu_num_cores();
|
| + int cores_set = 0;
|
|
|
| -void StorageQuotaCallbacksImpl::didQueryStorageUsageAndQuota(unsigned long long usageInBytes, unsigned long long quotaInBytes)
|
| -{
|
| - m_resolver->resolve(StorageInfo::create(usageInBytes, quotaInBytes));
|
| -}
|
| + cpu_set_t* cpup = CPU_ALLOC(num_cores);
|
| + GPR_ASSERT(cpup);
|
| + const size_t size = CPU_ALLOC_SIZE(num_cores);
|
| + CPU_ZERO_S(size, cpup);
|
|
|
| -void StorageQuotaCallbacksImpl::didGrantStorageQuota(unsigned long long usageInBytes, unsigned long long grantedQuotaInBytes)
|
| -{
|
| - m_resolver->resolve(StorageInfo::create(usageInBytes, grantedQuotaInBytes));
|
| + if (cores_size > 0) {
|
| + for (int i = 0; i < cores_size; i++) {
|
| + if (cores[i] < num_cores) {
|
| + CPU_SET_S(cores[i], size, cpup);
|
| + cores_set++;
|
| + }
|
| + }
|
| + } else {
|
| + for (int i = 0; i < num_cores; i++) {
|
| + CPU_SET_S(i, size, cpup);
|
| + cores_set++;
|
| + }
|
| + }
|
| + GPR_ASSERT(sched_setaffinity(0, size, cpup) == 0);
|
| + CPU_FREE(cpup);
|
| + return cores_set;
|
| }
|
| -
|
| -void StorageQuotaCallbacksImpl::didFail(WebStorageQuotaError error)
|
| -{
|
| - m_resolver->reject(DOMError::create(static_cast<ExceptionCode>(error)));
|
| -}
|
| -
|
| -DEFINE_TRACE(StorageQuotaCallbacksImpl)
|
| -{
|
| - visitor->trace(m_resolver);
|
| - StorageQuotaCallbacks::trace(visitor);
|
| -}
|
| -
|
| -} // namespace blink
|
| +#else
|
| +// LimitCores is not currently supported for non-Linux platforms
|
| +int LimitCores(const int*, int) { return gpr_cpu_num_cores(); }
|
| +#endif
|
| +} // namespace testing
|
| +} // namespace grpc
|
|
|