diff options
Diffstat (limited to 'src/collectors/perf.plugin')
-rw-r--r-- | src/collectors/perf.plugin/integrations/cpu_performance.md | 10 | ||||
-rw-r--r-- | src/collectors/perf.plugin/metadata.yaml | 2 | ||||
-rw-r--r-- | src/collectors/perf.plugin/perf_plugin.c | 49 |
3 files changed, 38 insertions, 23 deletions
diff --git a/src/collectors/perf.plugin/integrations/cpu_performance.md b/src/collectors/perf.plugin/integrations/cpu_performance.md index c24a14a99..0db211167 100644 --- a/src/collectors/perf.plugin/integrations/cpu_performance.md +++ b/src/collectors/perf.plugin/integrations/cpu_performance.md @@ -97,21 +97,21 @@ There are no alerts configured by default for this integration. #### Install perf plugin -If you are [using our official native DEB/RPM packages](/packaging/installer/UPDATE.md#determine-which-installation-method-you-used), make sure the `netdata-plugin-perf` package is installed. +If you are [using our official native DEB/RPM packages](https://github.com/netdata/netdata/blob/master/packaging/installer/UPDATE.md#determine-which-installation-method-you-used), make sure the `netdata-plugin-perf` package is installed. #### Enable the perf plugin The plugin is disabled by default because the number of PMUs is usually quite limited and it is not desired to allow Netdata to struggle silently for PMUs, interfering with other performance monitoring software. -To enable it, use `edit-config` from the Netdata [config directory](/docs/netdata-agent/configuration/README.md), which is typically at `/etc/netdata`, to edit the `netdata.conf` file. +To enable it, use `edit-config` from the Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md), which is typically at `/etc/netdata`, to edit the `netdata.conf` file. ```bash cd /etc/netdata # Replace this path with your Netdata config directory, if different sudo ./edit-config netdata.conf ``` -Change the value of the `perf` setting to `yes` in the `[plugins]` section. Save the file and restart the Netdata Agent with `sudo systemctl restart netdata`, or the [appropriate method](/packaging/installer/README.md#maintaining-a-netdata-agent-installation) for your system. +Change the value of the `perf` setting to `yes` in the `[plugins]` section. Save the file and restart the Netdata Agent with `sudo systemctl restart netdata`, or the [appropriate method](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/start-stop-restart.md) for your system. @@ -132,8 +132,8 @@ The file format is a modified INI syntax. The general structure is: [section2] option3 = some third value ``` -You can edit the configuration file using the `edit-config` script from the -Netdata [config directory](/docs/netdata-agent/configuration/README.md#the-netdata-config-directory). +You can edit the configuration file using the [`edit-config`](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#edit-a-configuration-file-using-edit-config) script from the +Netdata [config directory](https://github.com/netdata/netdata/blob/master/docs/netdata-agent/configuration/README.md#the-netdata-config-directory). ```bash cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata diff --git a/src/collectors/perf.plugin/metadata.yaml b/src/collectors/perf.plugin/metadata.yaml index 18841d53a..d72be7f5d 100644 --- a/src/collectors/perf.plugin/metadata.yaml +++ b/src/collectors/perf.plugin/metadata.yaml @@ -55,7 +55,7 @@ modules: sudo ./edit-config netdata.conf ``` - Change the value of the `perf` setting to `yes` in the `[plugins]` section. Save the file and restart the Netdata Agent with `sudo systemctl restart netdata`, or the [appropriate method](/packaging/installer/README.md#maintaining-a-netdata-agent-installation) for your system. + Change the value of the `perf` setting to `yes` in the `[plugins]` section. Save the file and restart the Netdata Agent with `sudo systemctl restart netdata`, or the [appropriate method](/docs/netdata-agent/start-stop-restart.md) for your system. configuration: file: name: "netdata.conf" diff --git a/src/collectors/perf.plugin/perf_plugin.c b/src/collectors/perf.plugin/perf_plugin.c index 8fb4014e4..ccc7016e2 100644 --- a/src/collectors/perf.plugin/perf_plugin.c +++ b/src/collectors/perf.plugin/perf_plugin.c @@ -240,7 +240,7 @@ static struct perf_event { {EV_ID_END, 0, 0, NULL, NULL, 0, 0, 0, NULL, NULL, NULL} }; -static int perf_init() { +static bool perf_init() { int cpu, group; struct perf_event_attr perf_event_attr; struct perf_event *current_event = NULL; @@ -270,6 +270,8 @@ static int perf_init() { memset(&perf_event_attr, 0, sizeof(perf_event_attr)); + int enabled = 0; + for(cpu = 0; cpu < number_of_cpus; cpu++) { for(current_event = &perf_events[0]; current_event->id != EV_ID_END; current_event++) { if(unlikely(current_event->disabled)) continue; @@ -304,6 +306,8 @@ static int perf_init() { } collector_error("Disabling event %u", current_event->id); current_event->disabled = 1; + } else { + enabled++; } *(current_event->fd + cpu) = fd; @@ -313,7 +317,7 @@ static int perf_init() { } } - return 0; + return enabled > 0; } static void perf_free(void) { @@ -1283,7 +1287,6 @@ void parse_command_line(int argc, char **argv) { } int main(int argc, char **argv) { - clocks_init(); nd_log_initialize_for_external_plugins("perf.plugin"); parse_command_line(argc, argv); @@ -1295,8 +1298,16 @@ int main(int argc, char **argv) { else if(freq) collector_error("update frequency %d seconds is too small for PERF. Using %d.", freq, update_every); - if(unlikely(debug)) fprintf(stderr, "perf.plugin: calling perf_init()\n"); - int perf = !perf_init(); + if (unlikely(debug)) + fprintf(stderr, "perf.plugin: calling perf_init()\n"); + + if (!perf_init()) { + perf_free(); + collector_info("all perf counters are disabled"); + fprintf(stdout, "EXIT\n"); + fflush(stdout); + exit(1); + } // ------------------------------------------------------------------------ // the main loop @@ -1306,27 +1317,30 @@ int main(int argc, char **argv) { time_t started_t = now_monotonic_sec(); size_t iteration; - usec_t step = update_every * USEC_PER_SEC; + + int perf = 1; heartbeat_t hb; - heartbeat_init(&hb); + heartbeat_init(&hb, update_every * USEC_PER_SEC); for(iteration = 0; 1; iteration++) { - usec_t dt = heartbeat_next(&hb, step); + usec_t dt = heartbeat_next(&hb); - if(unlikely(netdata_exit)) break; + if (unlikely(netdata_exit)) + break; - if(unlikely(debug && iteration)) - fprintf(stderr, "perf.plugin: iteration %zu, dt %"PRIu64" usec\n" - , iteration - , dt - ); + if (unlikely(debug && iteration)) + fprintf(stderr, "perf.plugin: iteration %zu, dt %" PRIu64 " usec\n", iteration, dt); if(likely(perf)) { - if(unlikely(debug)) fprintf(stderr, "perf.plugin: calling perf_collect()\n"); + if (unlikely(debug)) + fprintf(stderr, "perf.plugin: calling perf_collect()\n"); + perf = !perf_collect(); if(likely(perf)) { - if(unlikely(debug)) fprintf(stderr, "perf.plugin: calling perf_send_metrics()\n"); + if (unlikely(debug)) + fprintf(stderr, "perf.plugin: calling perf_send_metrics()\n"); + perf_send_metrics(); } } @@ -1334,7 +1348,8 @@ int main(int argc, char **argv) { fflush(stdout); // restart check (14400 seconds) - if(now_monotonic_sec() - started_t > 14400) break; + if (now_monotonic_sec() - started_t > 14400) + break; } collector_info("process exiting"); |