From 9484dab34a1dcdc5fc438ae5732bda9c757af071 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 21 Sep 2016 16:31:33 +0900 Subject: [PATCH] DO NOT MERGE Move Stopwatch into its own header Bug: 29748723 Test: netd_integration_test (cherry picked from commit cc544162e08dd0df271cd77a3f2c85dbaaa461e2) Change-Id: Icc2f633206b9f8052ca9ae2b775984b4f4be97b9 --- client/NetdClient.cpp | 1 + include/Stopwatch.h | 37 +++++++++++++++++++++++++++++++++++++ server/DnsProxyListener.cpp | 1 + server/NetdConstants.h | 15 --------------- server/SockDiag.cpp | 1 + tests/binder_test.cpp | 1 + 6 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 include/Stopwatch.h diff --git a/client/NetdClient.cpp b/client/NetdClient.cpp index 392b0af..91d630d 100644 --- a/client/NetdClient.cpp +++ b/client/NetdClient.cpp @@ -26,6 +26,7 @@ #include "FwmarkClient.h" #include "FwmarkCommand.h" #include "resolv_netid.h" +#include "Stopwatch.h" namespace { diff --git a/include/Stopwatch.h b/include/Stopwatch.h new file mode 100644 index 0000000..996ecdb --- /dev/null +++ b/include/Stopwatch.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NETD_INCLUDE_STOPWATCH_H +#define NETD_INCLUDE_STOPWATCH_H + +#include + +class Stopwatch { +public: + Stopwatch() : mStart(std::chrono::steady_clock::now()) {} + virtual ~Stopwatch() {}; + + float timeTaken() const { + using ms = std::chrono::duration>; + return (std::chrono::duration_cast( + std::chrono::steady_clock::now() - mStart)).count(); + } + +private: + std::chrono::time_point mStart; +}; + +#endif // NETD_INCLUDE_STOPWATCH_H diff --git a/server/DnsProxyListener.cpp b/server/DnsProxyListener.cpp index 049fb38..2a5ecc0 100644 --- a/server/DnsProxyListener.cpp +++ b/server/DnsProxyListener.cpp @@ -45,6 +45,7 @@ #include "NetdConstants.h" #include "NetworkController.h" #include "ResponseCode.h" +#include "Stopwatch.h" #include "android/net/metrics/INetdEventListener.h" using android::String16; diff --git a/server/NetdConstants.h b/server/NetdConstants.h index 605362c..f283ed0 100644 --- a/server/NetdConstants.h +++ b/server/NetdConstants.h @@ -60,21 +60,6 @@ int parsePrefix(const char *prefix, uint8_t *family, void *address, int size, ui const uid_t INVALID_UID = static_cast(-1); -class Stopwatch { -public: - Stopwatch() : mStart(std::chrono::steady_clock::now()) {} - virtual ~Stopwatch() {}; - - float timeTaken() const { - using ms = std::chrono::duration>; - return (std::chrono::duration_cast( - std::chrono::steady_clock::now() - mStart)).count(); - } - -private: - std::chrono::time_point mStart; -}; - struct AddrinfoDeleter { void operator()(struct addrinfo* p) const { diff --git a/server/SockDiag.cpp b/server/SockDiag.cpp index 1517b94..11711af 100644 --- a/server/SockDiag.cpp +++ b/server/SockDiag.cpp @@ -35,6 +35,7 @@ #include "NetdConstants.h" #include "Permission.h" #include "SockDiag.h" +#include "Stopwatch.h" #include diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp index fd94d2e..5395f1d 100644 --- a/tests/binder_test.cpp +++ b/tests/binder_test.cpp @@ -42,6 +42,7 @@ #include #include "NetdConstants.h" +#include "Stopwatch.h" #include "android/net/INetd.h" #include "android/net/UidRange.h" #include "binder/IServiceManager.h" -- 2.11.0