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

Unified Diff: third_party/grpc/test/cpp/qps/usage_timer.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/usage_timer.h ('k') | third_party/grpc/test/cpp/qps/worker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/grpc/test/cpp/qps/usage_timer.cc
diff --git a/third_party/tcmalloc/vendor/src/base/synchronization_profiling.h b/third_party/grpc/test/cpp/qps/usage_timer.cc
similarity index 63%
copy from third_party/tcmalloc/vendor/src/base/synchronization_profiling.h
copy to third_party/grpc/test/cpp/qps/usage_timer.cc
index cf02c218a111806189f71f7b528a83b5ceb164a4..6663a9ac1036b65727dadaf491bd5823b03626ff 100644
--- a/third_party/tcmalloc/vendor/src/base/synchronization_profiling.h
+++ b/third_party/grpc/test/cpp/qps/usage_timer.cc
@@ -1,4 +1,6 @@
-/* Copyright (c) 2010, Google Inc.
+/*
+ *
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,24 +29,43 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * ---
- * Author: Chris Ruemmler
*/
-#ifndef BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
-#define BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
+#include "test/cpp/qps/usage_timer.h"
+
+#include <grpc/support/time.h>
+#include <sys/resource.h>
+#include <sys/time.h>
-#include "base/basictypes.h"
+UsageTimer::UsageTimer() : start_(Sample()) {}
-namespace base {
+double UsageTimer::Now() {
+ auto ts = gpr_now(GPR_CLOCK_REALTIME);
+ return ts.tv_sec + 1e-9 * ts.tv_nsec;
+}
-// We can do contention-profiling of SpinLocks, but the code is in
-// mutex.cc, which is not always linked in with spinlock. Hence we
-// provide a weak definition, which are used if mutex.cc isn't linked in.
+static double time_double(struct timeval* tv) {
+ return tv->tv_sec + 1e-6 * tv->tv_usec;
+}
+
+UsageTimer::Result UsageTimer::Sample() {
+ struct rusage usage;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ getrusage(RUSAGE_SELF, &usage);
+
+ Result r;
+ r.wall = time_double(&tv);
+ r.user = time_double(&usage.ru_utime);
+ r.system = time_double(&usage.ru_stime);
+ return r;
+}
-// Submit the number of cycles the spinlock spent contending.
-ATTRIBUTE_WEAK extern void SubmitSpinLockProfileData(const void *, int64);
-extern void SubmitSpinLockProfileData(const void *contendedlock,
- int64 wait_cycles) {}
+UsageTimer::Result UsageTimer::Mark() const {
+ Result s = Sample();
+ Result r;
+ r.wall = s.wall - start_.wall;
+ r.user = s.user - start_.user;
+ r.system = s.system - start_.system;
+ return r;
}
-#endif // BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
« no previous file with comments | « third_party/grpc/test/cpp/qps/usage_timer.h ('k') | third_party/grpc/test/cpp/qps/worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698