Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: third_party/grpc/test/cpp/qps/limit_cores.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/grpc/test/cpp/qps/limit_cores.h ('k') | third_party/grpc/test/cpp/qps/perf_db_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/grpc/test/cpp/qps/limit_cores.h ('k') | third_party/grpc/test/cpp/qps/perf_db_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698