Lines Matching defs:counter

10 #include <cobalt-client/cpp/counter-internal.h>
11 #include <cobalt-client/cpp/counter.h>
47 BaseCounter counter;
49 ASSERT_EQ(counter.Load(), 0);
50 counter.Increment();
51 ASSERT_EQ(counter.Load(), 1);
52 counter.Increment();
53 ASSERT_EQ(counter.Load(), 2);
60 BaseCounter counter;
62 ASSERT_EQ(counter.Load(), 0);
63 counter.Increment(23);
64 ASSERT_EQ(counter.Load(), 23);
72 BaseCounter counter;
74 counter.Increment(24);
75 ASSERT_EQ(counter.Load(), 24);
76 EXPECT_EQ(counter.Exchange(), 24);
77 ASSERT_EQ(counter.Load(), 0);
85 BaseCounter counter;
87 counter.Increment(4);
88 ASSERT_EQ(counter.Load(), 4);
89 EXPECT_EQ(counter.Exchange(3), 4);
90 ASSERT_EQ(counter.Load(), 3);
91 EXPECT_EQ(counter.Exchange(2), 3);
92 ASSERT_EQ(counter.Load(), 2);
98 BaseCounter* counter;
103 // Amount to increment the counter with.
111 increment_args->counter->Increment(increment_args->value);
119 BaseCounter counter;
130 args[i].counter = &counter;
144 // Each thread should increase the counter by a total of value^2, which yields a total of:
146 ASSERT_EQ(counter.Load(), kThreads * (kThreads + 1) * (2 * kThreads + 1) / 6);
152 BaseCounter* counter;
154 // Accumulated value of exchanged values in the counter.
160 // Amount to increment the counter with.
166 // value of the counter to the accumulated atomic obtain a deterministic result.
170 BaseCounter::Type value = exchange_args->counter->Exchange(exchange_args->value);
177 // the result should be the same as above except that we need to add counter.Load() +
182 BaseCounter counter;
194 args[i].counter = &counter;
209 // Each thread should increase the counter by a total of value, which yields a total of:
211 ASSERT_EQ(counter.Load() + accumulated.load(fbl::memory_order_relaxed),
230 // Verify that the metadata used to create the counter is part of the flushes observation
231 // and that the current value of the counter is correct, plus resets to 0 after flush.
235 RemoteCounter counter = MakeRemoteCounter();
237 counter.Increment(20);
246 ASSERT_TRUE(counter.Flush([&](uint64_t metric_id, const EventBuffer<uint32_t>& buffer,
262 ASSERT_FALSE(counter.Flush(RemoteCounter::FlushFn()));
264 ASSERT_EQ(counter.Load(), 0);
265 ASSERT_TRUE(counter.Flush([](uint64_t metric_id, const EventBuffer<uint32_t>& val,
272 RemoteCounter* counter;
292 flush_args->counter->Flush([&flush_args](uint64_t metric_id,
299 flush_args->counter->Increment();
306 // the counter, kThreads flushing, and at the end we flush again, and the accumulated counter should
311 RemoteCounter counter = MakeRemoteCounter();
323 args[i].counter = &counter;
345 ASSERT_EQ(counter.Load() + accumulated.load(fbl::memory_order_relaxed),
372 Counter counter(&remote_counter);
374 ASSERT_EQ(counter.GetRemoteCount(), 0);
375 counter.Increment();
376 ASSERT_EQ(counter.GetRemoteCount(), 1);
377 counter.Increment(24);
378 ASSERT_EQ(counter.GetRemoteCount(), 25);
384 Counter* counter;
398 increment_args->counter->Increment(increment_args->times);
407 Counter counter(&remote_counter);
418 args[i].counter = &counter;
432 // Each thread should increase the counter by a total of value^2, which yields a total of:
434 ASSERT_EQ(counter.GetRemoteCount(), kThreads * (kThreads + 1) * (2 * kThreads + 1) / 6);