Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ set(SENSOR_SOURCES
src/config.c
src/util.c
src/target.c
src/target_docker.c
src/target_kubernetes.c
src/pmu.c
src/events.c
src/hwinfo.c
Expand Down
2 changes: 1 addition & 1 deletion src/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ main(int argc, char **argv)

/* start system monitoring actor only when needed */
if (zhashx_size(config->events.system)) {
system_target = target_create(TARGET_TYPE_ALL, NULL, NULL);
system_target = target_create(TARGET_TYPE_GLOBAL, NULL, NULL);
system_monitor_config = perf_config_create(hwinfo, config->events.system, system_target);
system_perf_monitor = zactor_new(perf_monitoring_actor, system_monitor_config);
}
Expand Down
75 changes: 3 additions & 72 deletions src/target.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, INRIA
* Copyright (c) 2018, Inria
* Copyright (c) 2018, University of Lille
* All rights reserved.
*
Expand Down Expand Up @@ -38,60 +38,8 @@
#include <sys/stat.h>

#include "target.h"
#include "target_docker.h"
#include "target_kubernetes.h"


enum target_type
target_detect_type(const char *cgroup_path)
{
/* All running processes/threads (not a cgroup) */
if (!cgroup_path)
return TARGET_TYPE_ALL;

/* System (running processes/threads in system cgroup) */
if (strstr(cgroup_path, "perf_event/system"))
return TARGET_TYPE_SYSTEM;

/* Kernel (running processes/threads in kernel cgroup) */
if (strstr(cgroup_path, "perf_event/kernel"))
return TARGET_TYPE_KERNEL;

/* Docker (running containers) */
if (strstr(cgroup_path, "perf_event/docker"))
return TARGET_TYPE_DOCKER;

/* Kubernetes (running containers) */
if (strstr(cgroup_path, "perf_event/kubepods"))
return TARGET_TYPE_KUBERNETES;

/* LibVirt (running virtual machine) */
if (strstr(cgroup_path, "perf_event/machine.slice"))
return TARGET_TYPE_LIBVIRT;

/* LXC (running containers) */
if (strstr(cgroup_path, "perf_event/lxc"))
return TARGET_TYPE_LXC;

return TARGET_TYPE_UNKNOWN;
}

int
target_validate_type(enum target_type type, const char *cgroup_path)
{
switch (type) {
case TARGET_TYPE_DOCKER:
return target_docker_validate(cgroup_path);

case TARGET_TYPE_KUBERNETES:
return target_kubernetes_validate(cgroup_path);

default:
/* other types does not need a validation */
return true;
}
}

struct target *
target_create(enum target_type type, const char *cgroup_basedir, const char *cgroup_path)
{
Expand All @@ -108,31 +56,15 @@
}

char *
target_resolve_real_name(struct target *target)

Check warning on line 59 in src/target.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "target" is "struct target *".

See more on https://sonarcloud.io/project/issues?id=powerapi-ng_hwpc-sensor&issues=AZ88GWilyrfTyaIdUbdq&open=AZ88GWilyrfTyaIdUbdq&pullRequest=194
{
char *target_real_name = NULL;

switch (target->type) {

Check warning on line 63 in src/target.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this "switch" statement by "if" statements to increase readability.

See more on https://sonarcloud.io/project/issues?id=powerapi-ng_hwpc-sensor&issues=AZ88GWilyrfTyaIdUbdr&open=AZ88GWilyrfTyaIdUbdr&pullRequest=194
case TARGET_TYPE_DOCKER:
target_real_name = target_docker_resolve_name(target);
break;

case TARGET_TYPE_KUBERNETES:
target_real_name = target_kubernetes_resolve_name(target);
break;

case TARGET_TYPE_ALL:
case TARGET_TYPE_GLOBAL:
target_real_name = strdup("all");
break;

case TARGET_TYPE_KERNEL:
target_real_name = strdup("kernel");
break;

case TARGET_TYPE_SYSTEM:
target_real_name = strdup("system");
break;

default:
break;
}
Expand Down Expand Up @@ -161,7 +93,6 @@
const char *path[] = { base_path, NULL };
FTS *file_system = NULL;
FTSENT *node = NULL;
enum target_type type = TARGET_TYPE_UNKNOWN;
struct target *target = NULL;

file_system = fts_open((char * const *) path, FTS_PHYSICAL | FTS_NOCHDIR | FTS_NOSTAT, NULL);
Expand Down Expand Up @@ -192,7 +123,7 @@
if (node->fts_number != 0)
continue;

target = target_create(type, base_path, node->fts_path);
target = target_create(TARGET_TYPE_CGROUP, base_path, node->fts_path);
zhashx_insert(targets, node->fts_path, target);
}

Expand Down
23 changes: 3 additions & 20 deletions src/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@

#include <czmq.h>


/*
* target_type stores the supported target types.
*/
enum target_type
{
TARGET_TYPE_UNKNOWN = 1,
TARGET_TYPE_ALL = 2,
TARGET_TYPE_SYSTEM = 4,
TARGET_TYPE_KERNEL = 8,
TARGET_TYPE_DOCKER = 16,
TARGET_TYPE_KUBERNETES = 32,
TARGET_TYPE_LIBVIRT = 64,
TARGET_TYPE_LXC = 128,
TARGET_TYPE_EVERYTHING = 255
TARGET_TYPE_GLOBAL = 1,
TARGET_TYPE_CGROUP = 2,
};

/*
Expand All @@ -60,16 +54,6 @@ struct target
char *cgroup_path;
};

/*
* target_detect_type returns the target type of the given cgroup path.
*/
enum target_type target_detect_type(const char *cgroup_path);

/*
* target_validate_type validate the target type of the given cgroup path.
*/
int target_validate_type(enum target_type type, const char *cgroup_path);

/*
* target_create allocate the resources and configure the target.
*/
Expand All @@ -91,4 +75,3 @@ void target_destroy(struct target *target);
int target_discover_running(const char *base_path, zhashx_t *targets);

#endif /* TARGET_H */

130 changes: 0 additions & 130 deletions src/target_docker.c

This file was deleted.

48 changes: 0 additions & 48 deletions src/target_docker.h

This file was deleted.

Loading
Loading