@cryptotaxi247 / netdata-1 / commits / 7f7225dfa

Fix chart update ebpf.plugin (#13351)

thiagoftsm committed Jul 18, 2022 at 12:09 UTC 7f7225dfaa81a928df5e46db5274d18875c880cf
17 files changed +225 -272
collectors/ebpf.plugin/ebpf_cachestat.c
+17 -19
@@ -879,7 +879,7 @@ static int ebpf_send_systemd_cachestat_charts()
879 for (ect = ebpf_cgroup_pids; ect; ect = ect->next) {
880 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
881 write_chart_dimension(ect->name, (long long)ect->publish_cachestat.ratio);
882 - } else
882 + } else if (unlikely(ect->systemd))
883 ret = 0;
884 }
885 write_end_chart();
@@ -1079,32 +1079,30 @@ static void cachestat_collector(ebpf_module_t *em)
1079 int apps = em->apps_charts;
1080 int cgroups = em->cgroup_charts;
1081 int update_every = em->update_every;
1082 - int counter = update_every - 1;
1082 + heartbeat_t hb;
1083 + heartbeat_init(&hb);
1084 + usec_t step = update_every * USEC_PER_SEC;
1085 while (!close_ebpf_plugin) {
1084 - pthread_mutex_lock(&collect_data_mutex);
1085 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
1086 + (void)heartbeat_next(&hb, step);
1087
1087 - if (++counter == update_every) {
1088 - counter = 0;
1089 - if (apps)
1090 - read_apps_table();
1091 -
1092 - if (cgroups)
1093 - ebpf_update_cachestat_cgroup();
1088 + pthread_mutex_lock(&collect_data_mutex);
1089 + if (apps)
1090 + read_apps_table();
1091
1095 - pthread_mutex_lock(&lock);
1092 + if (cgroups)
1093 + ebpf_update_cachestat_cgroup();
1094
1097 - cachestat_send_global(&publish);
1095 + pthread_mutex_lock(&lock);
1096
1099 - if (apps)
1100 - ebpf_cache_send_apps_data(apps_groups_root_target);
1097 + cachestat_send_global(&publish);
1098
1102 - if (cgroups)
1103 - ebpf_cachestat_send_cgroup_data(update_every);
1099 + if (apps)
1100 + ebpf_cache_send_apps_data(apps_groups_root_target);
1101
1105 - pthread_mutex_unlock(&lock);
1106 - }
1102 + if (cgroups)
1103 + ebpf_cachestat_send_cgroup_data(update_every);
1104
1105 + pthread_mutex_unlock(&lock);
1106 pthread_mutex_unlock(&collect_data_mutex);
1107 }
1108 }
collectors/ebpf.plugin/ebpf_dcstat.c
+17 -19
@@ -868,7 +868,7 @@ static int ebpf_send_systemd_dc_charts()
868 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
869 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
870 write_chart_dimension(ect->name, (long long) ect->publish_dc.ratio);
871 - } else
871 + } else if (unlikely(ect->systemd))
872 ret = 0;
873 }
874 write_end_chart();
@@ -1008,32 +1008,30 @@ static void dcstat_collector(ebpf_module_t *em)
1008 int apps = em->apps_charts;
1009 int cgroups = em->cgroup_charts;
1010 int update_every = em->update_every;
1011 - int counter = update_every - 1;
1011 + heartbeat_t hb;
1012 + heartbeat_init(&hb);
1013 + usec_t step = update_every * USEC_PER_SEC;
1014 while (!close_ebpf_plugin) {
1013 - pthread_mutex_lock(&collect_data_mutex);
1014 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
1015 + (void)heartbeat_next(&hb, step);
1016
1016 - if (++counter == update_every) {
1017 - counter = 0;
1018 - if (apps)
1019 - read_apps_table();
1020 -
1021 - if (cgroups)
1022 - ebpf_update_dc_cgroup();
1017 + pthread_mutex_lock(&collect_data_mutex);
1018 + if (apps)
1019 + read_apps_table();
1020
1024 - pthread_mutex_lock(&lock);
1021 + if (cgroups)
1022 + ebpf_update_dc_cgroup();
1023
1026 - dcstat_send_global(&publish);
1024 + pthread_mutex_lock(&lock);
1025
1028 - if (apps)
1029 - ebpf_dcache_send_apps_data(apps_groups_root_target);
1026 + dcstat_send_global(&publish);
1027
1031 - if (cgroups)
1032 - ebpf_dc_send_cgroup_data(update_every);
1028 + if (apps)
1029 + ebpf_dcache_send_apps_data(apps_groups_root_target);
1030
1034 - pthread_mutex_unlock(&lock);
1035 - }
1031 + if (cgroups)
1032 + ebpf_dc_send_cgroup_data(update_every);
1033
1034 + pthread_mutex_unlock(&lock);
1035 pthread_mutex_unlock(&collect_data_mutex);
1036 }
1037 }
collectors/ebpf.plugin/ebpf_disk.c
+8 -12
@@ -729,22 +729,18 @@ static void disk_collector(ebpf_module_t *em)
729 ebpf_disk_read_hash, em);
730
731 int update_every = em->update_every;
732 - int counter = update_every - 1;
732 read_thread_closed = 0;
733 + heartbeat_t hb;
734 + heartbeat_init(&hb);
735 + usec_t step = update_every * USEC_PER_SEC;
736 while (!close_ebpf_plugin) {
735 - pthread_mutex_lock(&collect_data_mutex);
736 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
737 + (void)heartbeat_next(&hb, step);
738
738 - if (++counter == update_every) {
739 - counter = 0;
740 - pthread_mutex_lock(&lock);
741 - ebpf_remove_pointer_from_plot_disk(em);
742 - ebpf_latency_send_hd_data(update_every);
743 -
744 - pthread_mutex_unlock(&lock);
745 - }
739 + pthread_mutex_lock(&lock);
740 + ebpf_remove_pointer_from_plot_disk(em);
741 + ebpf_latency_send_hd_data(update_every);
742
747 - pthread_mutex_unlock(&collect_data_mutex);
743 + pthread_mutex_unlock(&lock);
744
745 ebpf_update_disks(em);
746 }
collectors/ebpf.plugin/ebpf_fd.c
+17 -20
@@ -559,7 +559,7 @@ static int ebpf_send_systemd_fd_charts(ebpf_module_t *em)
559 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
560 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
561 write_chart_dimension(ect->name, ect->publish_systemd_fd.open_call);
562 - } else
562 + } else if (unlikely(ect->systemd))
563 ret = 0;
564 }
565 write_end_chart();
@@ -657,33 +657,30 @@ static void fd_collector(ebpf_module_t *em)
657
658 int apps = em->apps_charts;
659 int cgroups = em->cgroup_charts;
660 - int update_every = em->update_every;
661 - int counter = update_every - 1;
660 + heartbeat_t hb;
661 + heartbeat_init(&hb);
662 + usec_t step = em->update_every * USEC_PER_SEC;
663 while (!close_ebpf_plugin) {
663 - pthread_mutex_lock(&collect_data_mutex);
664 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
664 + (void)heartbeat_next(&hb, step);
665
666 - if (++counter == update_every) {
667 - counter = 0;
668 - if (apps)
669 - read_apps_table();
670 -
671 - if (cgroups)
672 - ebpf_update_fd_cgroup();
666 + pthread_mutex_lock(&collect_data_mutex);
667 + if (apps)
668 + read_apps_table();
669
674 - pthread_mutex_lock(&lock);
670 + if (cgroups)
671 + ebpf_update_fd_cgroup();
672
676 - ebpf_fd_send_data(em);
673 + pthread_mutex_lock(&lock);
674
678 - if (apps)
679 - ebpf_fd_send_apps_data(em, apps_groups_root_target);
675 + ebpf_fd_send_data(em);
676
681 - if (cgroups)
682 - ebpf_fd_send_cgroup_data(em);
677 + if (apps)
678 + ebpf_fd_send_apps_data(em, apps_groups_root_target);
679
684 - pthread_mutex_unlock(&lock);
685 - }
680 + if (cgroups)
681 + ebpf_fd_send_cgroup_data(em);
682
683 + pthread_mutex_unlock(&lock);
684 pthread_mutex_unlock(&collect_data_mutex);
685 }
686 }
collectors/ebpf.plugin/ebpf_filesystem.c
+8 -12
@@ -582,22 +582,18 @@ static void filesystem_collector(ebpf_module_t *em)
582 NETDATA_THREAD_OPTION_JOINABLE, ebpf_filesystem_read_hash, em);
583
584 int update_every = em->update_every;
585 - int counter = update_every - 1;
585 + heartbeat_t hb;
586 + heartbeat_init(&hb);
587 + usec_t step = update_every * USEC_PER_SEC;
588 while (!close_ebpf_plugin || em->optional) {
587 - pthread_mutex_lock(&collect_data_mutex);
588 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
589 + (void)heartbeat_next(&hb, step);
590
590 - if (++counter == update_every) {
591 - counter = 0;
592 - pthread_mutex_lock(&lock);
591 + pthread_mutex_lock(&lock);
592
594 - ebpf_create_fs_charts(update_every);
595 - ebpf_histogram_send_data();
596 -
597 - pthread_mutex_unlock(&lock);
598 - }
593 + ebpf_create_fs_charts(update_every);
594 + ebpf_histogram_send_data();
595
600 - pthread_mutex_unlock(&collect_data_mutex);
596 + pthread_mutex_unlock(&lock);
597 }
598 }
599
collectors/ebpf.plugin/ebpf_hardirq.c
+11 -16
@@ -433,26 +433,21 @@ static void hardirq_collector(ebpf_module_t *em)
433 pthread_mutex_unlock(&lock);
434
435 // loop and read from published data until ebpf plugin is closed.
436 - int update_every = em->update_every;
437 - int counter = update_every - 1;
436 + heartbeat_t hb;
437 + heartbeat_init(&hb);
438 + usec_t step = em->update_every * USEC_PER_SEC;
439 while (!close_ebpf_plugin) {
439 - pthread_mutex_lock(&collect_data_mutex);
440 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
440 + (void)heartbeat_next(&hb, step);
441
442 - if (++counter == update_every) {
443 - counter = 0;
444 - pthread_mutex_lock(&lock);
442 + pthread_mutex_lock(&lock);
443
446 - // write dims now for all hitherto discovered IRQs.
447 - write_begin_chart(NETDATA_EBPF_SYSTEM_GROUP, "hardirq_latency");
448 - avl_traverse_lock(&hardirq_pub, hardirq_write_dims, NULL);
449 - hardirq_write_static_dims();
450 - write_end_chart();
451 -
452 - pthread_mutex_unlock(&lock);
453 - }
444 + // write dims now for all hitherto discovered IRQs.
445 + write_begin_chart(NETDATA_EBPF_SYSTEM_GROUP, "hardirq_latency");
446 + avl_traverse_lock(&hardirq_pub, hardirq_write_dims, NULL);
447 + hardirq_write_static_dims();
448 + write_end_chart();
449
455 - pthread_mutex_unlock(&collect_data_mutex);
450 + pthread_mutex_unlock(&lock);
451 }
452 }
453
collectors/ebpf.plugin/ebpf_mdflush.c
+9 -16
@@ -261,25 +261,18 @@ static void mdflush_collector(ebpf_module_t *em)
261 pthread_mutex_unlock(&lock);
262
263 // loop and read from published data until ebpf plugin is closed.
264 - int update_every = em->update_every;
265 - int counter = update_every - 1;
264 + heartbeat_t hb;
265 + heartbeat_init(&hb);
266 + usec_t step = em->update_every * USEC_PER_SEC;
267 while (!close_ebpf_plugin) {
267 - pthread_mutex_lock(&collect_data_mutex);
268 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
269 -
270 - if (++counter == update_every) {
271 - counter = 0;
272 - pthread_mutex_lock(&lock);
268 + (void)heartbeat_next(&hb, step);
269
274 - // write dims now for all hitherto discovered devices.
275 - write_begin_chart("mdstat", "mdstat_flush");
276 - avl_traverse_lock(&mdflush_pub, mdflush_write_dims, NULL);
277 - write_end_chart();
278 -
279 - pthread_mutex_unlock(&lock);
280 - }
270 + // write dims now for all hitherto discovered devices.
271 + write_begin_chart("mdstat", "mdstat_flush");
272 + avl_traverse_lock(&mdflush_pub, mdflush_write_dims, NULL);
273 + write_end_chart();
274
282 - pthread_mutex_unlock(&collect_data_mutex);
275 + pthread_mutex_unlock(&lock);
276 }
277 }
278
collectors/ebpf.plugin/ebpf_mount.c
+7 -12
@@ -352,22 +352,17 @@ static void mount_collector(ebpf_module_t *em)
352 netdata_thread_create(mount_thread.thread, mount_thread.name, NETDATA_THREAD_OPTION_JOINABLE,
353 ebpf_mount_read_hash, em);
354
355 - int update_every = em->update_every;
356 - int counter = update_every - 1;
355 + heartbeat_t hb;
356 + heartbeat_init(&hb);
357 + usec_t step = em->update_every * USEC_PER_SEC;
358 while (!close_ebpf_plugin) {
358 - pthread_mutex_lock(&collect_data_mutex);
359 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
359 + (void)heartbeat_next(&hb, step);
360
361 - if (++counter == update_every) {
362 - counter = 0;
363 - pthread_mutex_lock(&lock);
361 + pthread_mutex_lock(&lock);
362
365 - ebpf_mount_send_data();
366 -
367 - pthread_mutex_unlock(&lock);
368 - }
363 + ebpf_mount_send_data();
364
370 - pthread_mutex_unlock(&collect_data_mutex);
365 + pthread_mutex_unlock(&lock);
366 }
367 }
368
collectors/ebpf.plugin/ebpf_oomkill.c
+17 -19
@@ -160,7 +160,7 @@ static int ebpf_send_systemd_oomkill_charts()
160 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
161 write_chart_dimension(ect->name, (long long) ect->oomkill);
162 ect->oomkill = 0;
163 - } else
163 + } else if (unlikely(ect->systemd))
164 ret = 0;
165 }
166 write_end_chart();
@@ -313,34 +313,32 @@ static void oomkill_collector(ebpf_module_t *em)
313 {
314 int cgroups = em->cgroup_charts;
315 int update_every = em->update_every;
316 - int counter = update_every - 1;
316 int32_t keys[NETDATA_OOMKILL_MAX_ENTRIES];
317 memset(keys, 0, sizeof(keys));
318
319 // loop and read until ebpf plugin is closed.
320 + heartbeat_t hb;
321 + heartbeat_init(&hb);
322 + usec_t step = update_every * USEC_PER_SEC;
323 while (!close_ebpf_plugin) {
322 - pthread_mutex_lock(&collect_data_mutex);
323 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
324 -
325 - if (++counter == update_every) {
326 - counter = 0;
327 - pthread_mutex_lock(&lock);
324 + (void)heartbeat_next(&hb, step);
325
329 - uint32_t count = oomkill_read_data(keys);
330 - if (cgroups && count)
331 - ebpf_update_oomkill_cgroup(keys, count);
326 + pthread_mutex_lock(&collect_data_mutex);
327 + pthread_mutex_lock(&lock);
328
333 - // write everything from the ebpf map.
334 - if (cgroups)
335 - ebpf_oomkill_send_cgroup_data(update_every);
329 + uint32_t count = oomkill_read_data(keys);
330 + if (cgroups && count)
331 + ebpf_update_oomkill_cgroup(keys, count);
332
337 - write_begin_chart(NETDATA_APPS_FAMILY, NETDATA_OOMKILL_CHART);
338 - oomkill_write_data(keys, count);
339 - write_end_chart();
333 + // write everything from the ebpf map.
334 + if (cgroups)
335 + ebpf_oomkill_send_cgroup_data(update_every);
336
341 - pthread_mutex_unlock(&lock);
342 - }
337 + write_begin_chart(NETDATA_APPS_FAMILY, NETDATA_OOMKILL_CHART);
338 + oomkill_write_data(keys, count);
339 + write_end_chart();
340
341 + pthread_mutex_unlock(&lock);
342 pthread_mutex_unlock(&collect_data_mutex);
343 }
344 }
collectors/ebpf.plugin/ebpf_process.c
+11 -6
@@ -884,7 +884,7 @@ static int ebpf_send_systemd_process_charts(ebpf_module_t *em)
884 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
885 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
886 write_chart_dimension(ect->name, ect->publish_systemd_ps.create_process);
887 - } else
887 + } else if (unlikely(ect->systemd))
888 ret = 0;
889 }
890 write_end_chart();
@@ -1031,20 +1031,23 @@ static void process_collector(ebpf_module_t *em)
1031 if (cgroups)
1032 ebpf_process_update_cgroup_algorithm();
1033
1034 + int update_apps_every = (int) EBPF_CFG_UPDATE_APPS_EVERY_DEFAULT;
1035 int pid_fd = process_maps[NETDATA_PROCESS_PID_TABLE].map_fd;
1036 int update_every = em->update_every;
1037 int counter = update_every - 1;
1038 + int update_apps_list = update_apps_every - 1;
1039 while (!close_ebpf_plugin) {
1040 usec_t dt = heartbeat_next(&hb, USEC_PER_SEC);
1041 (void)dt;
1042
1043 pthread_mutex_lock(&collect_data_mutex);
1042 - cleanup_exited_pids();
1043 - collect_data_for_all_processes(pid_fd);
1044 + if (++update_apps_list == update_apps_every) {
1045 + update_apps_list = 0;
1046 + cleanup_exited_pids();
1047 + collect_data_for_all_processes(pid_fd);
1048
1045 - ebpf_create_apps_charts(apps_groups_root_target);
1046 -
1047 - pthread_cond_broadcast(&collect_data_cond_var);
1049 + ebpf_create_apps_charts(apps_groups_root_target);
1050 + }
1051 pthread_mutex_unlock(&collect_data_mutex);
1052
1053 if (++counter == update_every) {
@@ -1053,6 +1056,7 @@ static void process_collector(ebpf_module_t *em)
1056 read_hash_global_tables();
1057
1058 int publish_apps = 0;
1059 + pthread_mutex_lock(&collect_data_mutex);
1060 if (all_pids_count > 0) {
1061 if (apps_enabled) {
1062 publish_apps = 1;
@@ -1081,6 +1085,7 @@ static void process_collector(ebpf_module_t *em)
1085 }
1086 }
1087 pthread_mutex_unlock(&lock);
1088 + pthread_mutex_unlock(&collect_data_mutex);
1089 }
1090
1091 fflush(stdout);
collectors/ebpf.plugin/ebpf_shm.c
+20 -22
@@ -729,7 +729,7 @@ static int ebpf_send_systemd_shm_charts()
729 for (ect = ebpf_cgroup_pids; ect; ect = ect->next) {
730 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
731 write_chart_dimension(ect->name, (long long)ect->publish_shm.get);
732 - } else
732 + } else if (unlikely(ect->systemd))
733 ret = 0;
734 }
735 write_end_chart();
@@ -856,36 +856,34 @@ static void shm_collector(ebpf_module_t *em)
856 int apps = em->apps_charts;
857 int cgroups = em->cgroup_charts;
858 int update_every = em->update_every;
859 - int counter = update_every - 1;
859 + heartbeat_t hb;
860 + heartbeat_init(&hb);
861 + usec_t step = update_every * USEC_PER_SEC;
862 while (!close_ebpf_plugin) {
861 - pthread_mutex_lock(&collect_data_mutex);
862 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
863 + (void)heartbeat_next(&hb, step);
864
864 - if (++counter == update_every) {
865 - counter = 0;
866 - if (apps) {
867 - read_apps_table();
868 - }
869 -
870 - if (cgroups) {
871 - ebpf_update_shm_cgroup();
872 - }
865 + pthread_mutex_lock(&collect_data_mutex);
866 + if (apps) {
867 + read_apps_table();
868 + }
869
874 - pthread_mutex_lock(&lock);
870 + if (cgroups) {
871 + ebpf_update_shm_cgroup();
872 + }
873
876 - shm_send_global();
874 + pthread_mutex_lock(&lock);
875
878 - if (apps) {
879 - ebpf_shm_send_apps_data(apps_groups_root_target);
880 - }
876 + shm_send_global();
877
882 - if (cgroups) {
883 - ebpf_shm_send_cgroup_data(update_every);
884 - }
878 + if (apps) {
879 + ebpf_shm_send_apps_data(apps_groups_root_target);
880 + }
881
886 - pthread_mutex_unlock(&lock);
882 + if (cgroups) {
883 + ebpf_shm_send_cgroup_data(update_every);
884 }
885
886 + pthread_mutex_unlock(&lock);
887 pthread_mutex_unlock(&collect_data_mutex);
888 }
889 }
collectors/ebpf.plugin/ebpf_socket.c
+30 -36
@@ -2502,7 +2502,7 @@ static int ebpf_send_systemd_socket_charts()
2502 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
2503 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
2504 write_chart_dimension(ect->name, (long long)ect->publish_socket.call_tcp_v4_connection);
2505 - } else
2505 + } else if (unlikely(ect->systemd))
2506 ret = 0;
2507 }
2508 write_end_chart();
@@ -2655,7 +2655,6 @@ struct netdata_static_thread socket_threads = {"EBPF SOCKET READ",
2655 */
2656 static void socket_collector(usec_t step, ebpf_module_t *em)
2657 {
2658 - UNUSED(step);
2658 heartbeat_t hb;
2659 heartbeat_init(&hb);
2660
@@ -2672,54 +2671,49 @@ static void socket_collector(usec_t step, ebpf_module_t *em)
2671 int socket_global_enabled = ebpf_modules[EBPF_MODULE_SOCKET_IDX].global_charts;
2672 int network_connection = em->optional;
2673 int update_every = em->update_every;
2675 - int counter = update_every - 1;
2674 while (!close_ebpf_plugin) {
2675 + (void)heartbeat_next(&hb, step);
2676 +
2677 pthread_mutex_lock(&collect_data_mutex);
2678 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
2678 + if (socket_global_enabled)
2679 + read_hash_global_tables();
2680
2680 - if (++counter == update_every) {
2681 - counter = 0;
2682 - if (socket_global_enabled)
2683 - read_hash_global_tables();
2681 + if (socket_apps_enabled)
2682 + ebpf_socket_update_apps_data();
2683
2685 - if (socket_apps_enabled)
2686 - ebpf_socket_update_apps_data();
2684 + if (cgroups)
2685 + ebpf_update_socket_cgroup();
2686
2688 - if (cgroups)
2689 - ebpf_update_socket_cgroup();
2687 + calculate_nv_plot();
2688
2691 - calculate_nv_plot();
2689 + pthread_mutex_lock(&lock);
2690 + if (socket_global_enabled)
2691 + ebpf_socket_send_data(em);
2692
2693 - pthread_mutex_lock(&lock);
2694 - if (socket_global_enabled)
2695 - ebpf_socket_send_data(em);
2693 + if (socket_apps_enabled)
2694 + ebpf_socket_send_apps_data(em, apps_groups_root_target);
2695
2697 - if (socket_apps_enabled)
2698 - ebpf_socket_send_apps_data(em, apps_groups_root_target);
2696 + if (cgroups)
2697 + ebpf_socket_send_cgroup_data(update_every);
2698
2700 - if (cgroups)
2701 - ebpf_socket_send_cgroup_data(update_every);
2699 + fflush(stdout);
2700
2701 + if (network_connection) {
2702 + // We are calling fflush many times, because when we have a lot of dimensions
2703 + // we began to have not expected outputs and Netdata closed the plugin.
2704 + pthread_mutex_lock(&nv_mutex);
2705 + ebpf_socket_create_nv_charts(&inbound_vectors, update_every);
2706 fflush(stdout);
2707 + ebpf_socket_send_nv_data(&inbound_vectors);
2708
2705 - if (network_connection) {
2706 - // We are calling fflush many times, because when we have a lot of dimensions
2707 - // we began to have not expected outputs and Netdata closed the plugin.
2708 - pthread_mutex_lock(&nv_mutex);
2709 - ebpf_socket_create_nv_charts(&inbound_vectors, update_every);
2710 - fflush(stdout);
2711 - ebpf_socket_send_nv_data(&inbound_vectors);
2712 -
2713 - ebpf_socket_create_nv_charts(&outbound_vectors, update_every);
2714 - fflush(stdout);
2715 - ebpf_socket_send_nv_data(&outbound_vectors);
2716 - wait_to_plot = 0;
2717 - pthread_mutex_unlock(&nv_mutex);
2709 + ebpf_socket_create_nv_charts(&outbound_vectors, update_every);
2710 + fflush(stdout);
2711 + ebpf_socket_send_nv_data(&outbound_vectors);
2712 + wait_to_plot = 0;
2713 + pthread_mutex_unlock(&nv_mutex);
2714
2719 - }
2720 - pthread_mutex_unlock(&lock);
2715 }
2722 -
2716 + pthread_mutex_unlock(&lock);
2717 pthread_mutex_unlock(&collect_data_mutex);
2718 }
2719 }
collectors/ebpf.plugin/ebpf_softirq.c
+10 -14
@@ -214,24 +214,20 @@ static void softirq_collector(ebpf_module_t *em)
214 pthread_mutex_unlock(&lock);
215
216 // loop and read from published data until ebpf plugin is closed.
217 - int update_every = em->update_every;
218 - int counter = update_every - 1;
217 + heartbeat_t hb;
218 + heartbeat_init(&hb);
219 + usec_t step = em->update_every * USEC_PER_SEC;
220 while (!close_ebpf_plugin) {
220 - pthread_mutex_lock(&collect_data_mutex);
221 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
221 + (void)heartbeat_next(&hb, step);
222
223 - if (++counter == update_every) {
224 - counter = 0;
225 - pthread_mutex_lock(&lock);
223 + pthread_mutex_lock(&lock);
224
227 - // write dims now for all hitherto discovered IRQs.
228 - write_begin_chart(NETDATA_EBPF_SYSTEM_GROUP, "softirq_latency");
229 - softirq_write_dims();
230 - write_end_chart();
225 + // write dims now for all hitherto discovered IRQs.
226 + write_begin_chart(NETDATA_EBPF_SYSTEM_GROUP, "softirq_latency");
227 + softirq_write_dims();
228 + write_end_chart();
229
232 - pthread_mutex_unlock(&lock);
233 - }
234 - pthread_mutex_unlock(&collect_data_mutex);
230 + pthread_mutex_unlock(&lock);
231 }
232 }
233
collectors/ebpf.plugin/ebpf_swap.c
+17 -18
@@ -512,7 +512,7 @@ static int ebpf_send_systemd_swap_charts()
512 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
513 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
514 write_chart_dimension(ect->name, (long long) ect->publish_systemd_swap.read);
515 - } else
515 + } else if (unlikely(ect->systemd))
516 ret = 0;
517 }
518 write_end_chart();
@@ -685,31 +685,30 @@ static void swap_collector(ebpf_module_t *em)
685 int apps = em->apps_charts;
686 int cgroup = em->cgroup_charts;
687 int update_every = em->update_every;
688 - int counter = update_every - 1;
688 + heartbeat_t hb;
689 + heartbeat_init(&hb);
690 + usec_t step = update_every * USEC_PER_SEC;
691 while (!close_ebpf_plugin) {
690 - pthread_mutex_lock(&collect_data_mutex);
691 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
692 + (void)heartbeat_next(&hb, step);
693
693 - if (++counter == update_every) {
694 - counter = 0;
695 - if (apps)
696 - read_apps_table();
694 + pthread_mutex_lock(&collect_data_mutex);
695 + if (apps)
696 + read_apps_table();
697
698 - if (cgroup)
699 - ebpf_update_swap_cgroup();
698 + if (cgroup)
699 + ebpf_update_swap_cgroup();
700
701 - pthread_mutex_lock(&lock);
701 + pthread_mutex_lock(&lock);
702
703 - swap_send_global();
703 + swap_send_global();
704
705 - if (apps)
706 - ebpf_swap_send_apps_data(apps_groups_root_target);
705 + if (apps)
706 + ebpf_swap_send_apps_data(apps_groups_root_target);
707
708 - if (cgroup)
709 - ebpf_swap_send_cgroup_data(update_every);
708 + if (cgroup)
709 + ebpf_swap_send_cgroup_data(update_every);
710
711 - pthread_mutex_unlock(&lock);
712 - }
711 + pthread_mutex_unlock(&lock);
712 pthread_mutex_unlock(&collect_data_mutex);
713 }
714 }
collectors/ebpf.plugin/ebpf_sync.c
+7 -11
@@ -417,21 +417,17 @@ static void sync_collector(ebpf_module_t *em)
417 netdata_thread_create(sync_threads.thread, sync_threads.name, NETDATA_THREAD_OPTION_JOINABLE,
418 ebpf_sync_read_hash, em);
419
420 - int update_every = em->update_every;
421 - int counter = update_every - 1;
420 + heartbeat_t hb;
421 + heartbeat_init(&hb);
422 + usec_t step = em->update_every * USEC_PER_SEC;
423 while (!close_ebpf_plugin) {
423 - pthread_mutex_lock(&collect_data_mutex);
424 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
424 + (void)heartbeat_next(&hb, step);
425
426 - if (++counter == update_every) {
427 - counter = 0;
428 - pthread_mutex_lock(&lock);
426 + pthread_mutex_lock(&lock);
427
430 - sync_send_data();
428 + sync_send_data();
429
432 - pthread_mutex_unlock(&lock);
433 - }
434 - pthread_mutex_unlock(&collect_data_mutex);
430 + pthread_mutex_unlock(&lock);
431 }
432 }
433
collectors/ebpf.plugin/ebpf_vfs.c
+18 -20
@@ -987,7 +987,7 @@ static int ebpf_send_systemd_vfs_charts(ebpf_module_t *em)
987 for (ect = ebpf_cgroup_pids; ect ; ect = ect->next) {
988 if (unlikely(ect->systemd) && unlikely(ect->updated)) {
989 write_chart_dimension(ect->name, ect->publish_systemd_vfs.unlink_call);
990 - } else
990 + } else if (unlikely(ect->systemd))
991 ret = 0;
992 }
993 write_end_chart();
@@ -1173,33 +1173,31 @@ static void vfs_collector(ebpf_module_t *em)
1173
1174 int apps = em->apps_charts;
1175 int cgroups = em->cgroup_charts;
1176 - int update_every = em->update_every;
1177 - int counter = update_every - 1;
1176 + heartbeat_t hb;
1177 + heartbeat_init(&hb);
1178 + usec_t step = em->update_every * USEC_PER_SEC;
1179 while (!close_ebpf_plugin) {
1179 - pthread_mutex_lock(&collect_data_mutex);
1180 - pthread_cond_wait(&collect_data_cond_var, &collect_data_mutex);
1180 + (void)heartbeat_next(&hb, step);
1181
1182 - if (++counter == update_every) {
1183 - counter = 0;
1184 - if (apps)
1185 - ebpf_vfs_read_apps();
1182 + pthread_mutex_lock(&collect_data_mutex);
1183 + if (apps)
1184 + ebpf_vfs_read_apps();
1185
1187 - if (cgroups)
1188 - read_update_vfs_cgroup();
1186 + if (cgroups)
1187 + read_update_vfs_cgroup();
1188
1190 - pthread_mutex_lock(&lock);
1189 + pthread_mutex_lock(&lock);
1190
1192 - ebpf_vfs_send_data(em);
1193 - fflush(stdout);
1191 + ebpf_vfs_send_data(em);
1192 + fflush(stdout);
1193
1195 - if (apps)
1196 - ebpf_vfs_send_apps_data(em, apps_groups_root_target);
1194 + if (apps)
1195 + ebpf_vfs_send_apps_data(em, apps_groups_root_target);
1196
1198 - if (cgroups)
1199 - ebpf_vfs_send_cgroup_data(em);
1197 + if (cgroups)
1198 + ebpf_vfs_send_cgroup_data(em);
1199
1201 - pthread_mutex_unlock(&lock);
1202 - }
1200 + pthread_mutex_unlock(&lock);
1201 pthread_mutex_unlock(&collect_data_mutex);
1202 }
1203 }
libnetdata/ebpf/ebpf.h
+1
@@ -34,6 +34,7 @@
34 #define EBPF_CFG_PROGRAM_PATH "btf path"
35
36 #define EBPF_CFG_UPDATE_EVERY "update every"
37 +#define EBPF_CFG_UPDATE_APPS_EVERY_DEFAULT 10
38 #define EBPF_CFG_PID_SIZE "pid table size"
39 #define EBPF_CFG_APPLICATION "apps"
40 #define EBPF_CFG_CGROUP "cgroups"