Skip to content

Commit c45f937

Browse files
authored
Move prefetch codes into its own folder (istio#52)
* Move prefetch codes into its own folder. * Add prefetch/BUILD. * Update include quard. * Update comment to trigger a PR test.
1 parent c77ddb0 commit c45f937

7 files changed

+71
-39
lines changed

mixerclient/BUILD

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ cc_library(
3737
"src/signature.h",
3838
"src/stream_transport.h",
3939
"src/transport.h",
40-
"utils/circular_queue.h",
4140
"utils/md5.cc",
4241
"utils/md5.h",
4342
"utils/status_test_util.h",
44-
"utils/time_based_counter.cc",
45-
"utils/time_based_counter.h",
4643
],
4744
hdrs = [
4845
"include/attribute.h",
@@ -128,28 +125,6 @@ cc_test(
128125
],
129126
)
130127

131-
cc_test(
132-
name = "circular_queue_test",
133-
size = "small",
134-
srcs = ["utils/circular_queue_test.cc"],
135-
linkstatic = 1,
136-
deps = [
137-
":mixer_client_lib",
138-
"//external:googletest_main",
139-
],
140-
)
141-
142-
cc_test(
143-
name = "time_based_counter_test",
144-
size = "small",
145-
srcs = ["utils/time_based_counter_test.cc"],
146-
linkstatic = 1,
147-
deps = [
148-
":mixer_client_lib",
149-
"//external:googletest_main",
150-
],
151-
)
152-
153128
cc_test(
154129
name = "cache_key_set_test",
155130
size = "small",

mixerclient/prefetch/BUILD

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
licenses(["notice"])
16+
17+
cc_library(
18+
name = "quota_prefetch_lib",
19+
srcs = [
20+
"time_based_counter.cc",
21+
],
22+
hdrs = [
23+
"circular_queue.h",
24+
"time_based_counter.h",
25+
],
26+
visibility = ["//visibility:public"],
27+
)
28+
29+
cc_test(
30+
name = "circular_queue_test",
31+
size = "small",
32+
srcs = ["circular_queue_test.cc"],
33+
linkopts = [
34+
"-lm",
35+
"-lpthread",
36+
],
37+
linkstatic = 1,
38+
deps = [
39+
":quota_prefetch_lib",
40+
"//external:googletest_main",
41+
],
42+
)
43+
44+
cc_test(
45+
name = "time_based_counter_test",
46+
size = "small",
47+
srcs = ["time_based_counter_test.cc"],
48+
linkopts = [
49+
"-lm",
50+
"-lpthread",
51+
],
52+
linkstatic = 1,
53+
deps = [
54+
":quota_prefetch_lib",
55+
"//external:googletest_main",
56+
],
57+
)

mixerclient/utils/circular_queue.h renamed to mixerclient/prefetch/circular_queue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16-
#ifndef MIXER_CLIENT_UTILS_CIRCULAR_QUEUE_H_
17-
#define MIXER_CLIENT_UTILS_CIRCULAR_QUEUE_H_
16+
#ifndef MIXER_CLIENT_PREFETCH_CIRCULAR_QUEUE_H_
17+
#define MIXER_CLIENT_PREFETCH_CIRCULAR_QUEUE_H_
1818

1919
#include <functional>
2020
#include <vector>
@@ -94,4 +94,4 @@ void CircularQueue<T>::Iterate(std::function<bool(const T&)> fn) const {
9494
} // namespace mixer_client
9595
} // namespace istio
9696

97-
#endif // MIXER_CLIENT_CLIENT_UTILS_CIRCULAR_QUEUE_H_
97+
#endif // MIXER_CLIENT_CLIENT_PREFETCH_CIRCULAR_QUEUE_H_

mixerclient/utils/time_based_counter.cc renamed to mixerclient/prefetch/time_based_counter.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void TimeBasedCounter::Roll(Tick t) {
5050
}
5151
}
5252

53-
void TimeBasedCounter::Inc(Tick t) {
53+
void TimeBasedCounter::Inc(int n, Tick t) {
5454
Roll(t);
55-
slots_[tail_]++;
56-
count_++;
55+
slots_[tail_] += n;
56+
count_ += n;
5757
}
5858

5959
int TimeBasedCounter::Count(Tick t) {

mixerclient/utils/time_based_counter.h renamed to mixerclient/prefetch/time_based_counter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16-
#ifndef MIXER_CLIENT_UTILS_TIME_BASED_COUNTER_H_
17-
#define MIXER_CLIENT_UTILS_TIME_BASED_COUNTER_H_
16+
#ifndef MIXER_CLIENT_PREFETCH_TIME_BASED_COUNTER_H_
17+
#define MIXER_CLIENT_PREFETCH_TIME_BASED_COUNTER_H_
1818

1919
#include <chrono>
2020
#include <vector>
@@ -36,8 +36,8 @@ class TimeBasedCounter {
3636
// But for easy unit_test, pass the time in.
3737
// The input time should be always increasing.
3838

39-
// Add a count
40-
void Inc(Tick t);
39+
// Add n count to the counter.
40+
void Inc(int n, Tick t);
4141

4242
// Get the count.
4343
int Count(Tick t);
@@ -58,4 +58,4 @@ class TimeBasedCounter {
5858
} // namespace mixer_client
5959
} // namespace istio
6060

61-
#endif // MIXER_CLIENT_CLIENT_UTILS_TIME_BASED_COUNTER_H_
61+
#endif // MIXER_CLIENT_CLIENT_PREFETCH_TIME_BASED_COUNTER_H_

mixerclient/utils/time_based_counter_test.cc renamed to mixerclient/prefetch/time_based_counter_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ std::chrono::time_point<std::chrono::system_clock> FakeTime(int t) {
2727

2828
TEST(TimeBasedCounterTest, Test1) {
2929
TimeBasedCounter c(3, std::chrono::nanoseconds(3), FakeTime(0));
30-
c.Inc(FakeTime(4));
31-
c.Inc(FakeTime(5));
32-
c.Inc(FakeTime(7));
30+
c.Inc(1, FakeTime(4));
31+
c.Inc(1, FakeTime(5));
32+
c.Inc(1, FakeTime(7));
3333

3434
// Current slots are 6, 7, 8. and 4 and 5 are out.
3535
ASSERT_EQ(c.Count(FakeTime(8)), 1);

0 commit comments

Comments
 (0)