Debian Codegraph @

src/coro_loop/coro_loop.cpp

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ************************************************************************************/
22
23 #include <dpp/dpp.h>
24 #include <iostream>
25
26 int64_t proc_self_value(const std::string& find_token) {
27 int64_t ret = 0;
28 std::ifstream self_status("/proc/self/status");
29 while (self_status) {
30 std::string token;
31 self_status >> token;
32 if (token == find_token) {
33 self_status >> ret;
34 break;
35 }
36 }
37 self_status.close();
38 return ret;
39 }
40
41 int64_t rss() {
42 return proc_self_value("VmRSS:") * 1024;
43 }
44
45 #ifndef DPP_NO_CORO
46 dpp::task<void> test(dpp::cluster& cluster) {
47 [[maybe_unused]] int test[102400]{};
48 test[60] = 5;
49 co_return;
50 }
51 #endif
52
53 int main() {
54 #ifndef DPP_NO_CORO
55 char* t = getenv("DPP_UNIT_TEST_TOKEN");
56 if (t) {
57 dpp::cluster coro_cluster(t, dpp::i_guilds, 1, 0, 1, true, dpp::cache_policy::cpol_none);
58 coro_cluster.set_websocket_protocol(dpp::ws_etf);
59 coro_cluster.on_log(dpp::utility::cout_logger());
60 coro_cluster.on_ready([&coro_cluster](auto) -> dpp::task<void> {
61 coro_cluster.start_timer([&coro_cluster](dpp::timer) -> dpp::task<void> {
62 for (int i = 0; i < 1000; ++i) {
63 co_await test(coro_cluster);
64 }
65 coro_cluster.log(dpp::ll_info, "coro timer ticked. RSS=" + std::to_string(rss()));
66 co_return;
67 }, 1);
68 co_return;
69 });
70 coro_cluster.start(dpp::st_wait);
71 }
72 #endif
73 }