Skip to content

Commit

Permalink
cleaned up to libev based sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 9, 2021
1 parent 187528b commit f232cbd
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 322 deletions.
3 changes: 3 additions & 0 deletions monitor/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ esac],
[rabbitmq=false])
AM_CONDITIONAL([RABBITMQ], [test x$rabbitmq = xtrue])

AC_SEARCH_LIBS([ev_run], [ev], [libev=yes], [AC_MSG_ERROR([Failed to find lib libev.so])])
AC_CHECK_HEADERS([ev.h], [ev=true], [AC_MSG_ERROR([Failed to find header ev.h])])

AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

3 changes: 2 additions & 1 deletion monitor/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Makefile.in
stream
stream.c
vector
test.txt
test.txt
tacc_statsd
36 changes: 20 additions & 16 deletions monitor/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ACLOCAL_AMFLAGS = -I m4

bin_PROGRAMS = tacc_stats
bin_PROGRAMS = tacc_statsd

STATS_DIR_PATH = /var/log/tacc_stats
STATS_LOCK_PATH = /var/lock/tacc_stats
JOBID_FILE_PATH = /var/run/TACC_jobid

tacc_stats_CPPFLAGS = \
tacc_statsd_CPPFLAGS = \
-D_GNU_SOURCE \
-DSTATS_PROGRAM=\"@PACKAGE@\" \
-DSTATS_VERSION=\"@PACKAGE_VERSION@\" \
Expand All @@ -15,15 +15,19 @@ tacc_stats_CPPFLAGS = \
-DJOBID_FILE_PATH=\"$(JOBID_FILE_PATH)\"

if DEBUG
tacc_stats_CPPFLAGS += \
tacc_statsd_CPPFLAGS += \
-DDEBUG
endif

tacc_stats_SOURCES = \
tacc_statsd_SOURCES = \
amd64_pmc.h \
amd64_df.h \
collect.h \
collect.c \
cpuid.h \
cpuid.c \
daemonize.h \
daemonize.c \
dict.h \
dict.c \
intel_pmc3.h \
Expand All @@ -40,14 +44,14 @@ tacc_stats_SOURCES = \
trace.h

if RABBITMQ
tacc_stats_SOURCES += \
tacc_statsd_SOURCES += \
monitor.c \
stats_buffer.c \
stats_buffer.h
tacc_stats_CPPFLAGS += \
tacc_statsd_CPPFLAGS += \
-DRABBITMQ
else
tacc_stats_SOURCES += \
tacc_statsd_SOURCES += \
main.c \
stats_file.c \
stats_file.h
Expand Down Expand Up @@ -109,17 +113,17 @@ TYPES += \
ib_sw.c
endif

tacc_stats_LDFLAGS =
tacc_statsd_LDFLAGS =
if OPA
TYPES += \
opa.c
tacc_stats_LDFLAGS += \
tacc_statsd_LDFLAGS += \
-lpthread \
-lmemusage
endif

if LUSTRE
tacc_stats_SOURCES += \
tacc_statsd_SOURCES += \
lustre_obd_to_mnt.c \
lustre_obd_to_mnt.h

Expand All @@ -130,23 +134,23 @@ TYPES += \
endif

if MIC
tacc_stats_SOURCES += \
tacc_statsd_SOURCES += \
miclib.h
TYPES += \
mic.c
endif

tacc_stats_SOURCES += \
tacc_statsd_SOURCES += \
$(TYPES)

tacc_stats_LDFLAGS += \
tacc_statsd_LDFLAGS += \
-lm

nodist_tacc_stats_SOURCES = \
nodist_tacc_statsd_SOURCES = \
stats.x

if GPU
nodist_tacc_stats_SOURCES += \
nodist_tacc_statsd_SOURCES += \
nvml.h
TYPES += \
nvidia_gpu.c
Expand All @@ -164,7 +168,7 @@ initd_SCRIPTS = taccstats
sysconf_DATA = tacc_stats.conf
sysconf_DATA += taccstats.service
BUILT_SOURCES += taccstats
nodist_tacc_stats_SOURCES += \
nodist_tacc_statsd_SOURCES += \
taccstats
CLEANFILES += $(initd_SCRIPTS) $(sysconfdir_DATA)

Expand Down
85 changes: 85 additions & 0 deletions monitor/src/daemonize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "daemonize.h"
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#include <syslog.h>

void daemonize()
{
pid_t pid = 0;
int fd;

/* Fork off the parent process */
pid = fork();

/* An error occurred */
if (pid < 0) {
exit(EXIT_FAILURE);
}

/* Success: Let the parent terminate */
if (pid > 0) {
exit(EXIT_SUCCESS);
}

/* On success: The child process becomes session leader */
if (setsid() < 0) {
exit(EXIT_FAILURE);
}

/* Ignore signal sent from child to parent process */
signal(SIGCHLD, SIG_IGN);

/* Fork off for the second time*/
pid = fork();

/* An error occurred */
if (pid < 0) {
exit(EXIT_FAILURE);
}

/* Success: Let the parent terminate */
if (pid > 0) {
exit(EXIT_SUCCESS);
}

/* Set new file permissions */
umask(0);

/* Change the working directory to the root directory */
/* or another appropriated directory */
chdir("/");

/* Close all open file descriptors */
for (fd = sysconf(_SC_OPEN_MAX); fd > 0; fd--) {
close(fd);
}
/* Reopen stdin (fd = 0), stdout (fd = 1), stderr (fd = 2) */
stdin = fopen("/dev/null", "r");
stdout = fopen("/dev/null", "w+");
stderr = fopen("/dev/null", "w+");
/* Try to write PID of daemon to lockfile */
syslog(LOG_ERR,"%s\n",pid_file_name);
if (pid_file_name != NULL)
{
char str[256];
pid_fd = open(pid_file_name, O_RDWR|O_CREAT, 0640);
if (pid_fd < 0) {
/* Can't open lockfile */
exit(EXIT_FAILURE);
}
if (lockf(pid_fd, F_TLOCK, 0) < 0) {
/* Can't lock file */
syslog(LOG_ERR, "%s already found. Abort second instance.\n", pid_file_name);
exit(EXIT_FAILURE);
}
/* Get current PID */
sprintf(str, "%d\n", getpid());
/* Write PID to lockfile */
write(pid_fd, str, strlen(str));
}
}
10 changes: 10 additions & 0 deletions monitor/src/daemonize.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _DAEMONIZE_H_
#define _DAEMONIZE_H_

#include <stdlib.h>

int pid_fd;
char *pid_file_name;
void daemonize();

#endif
4 changes: 2 additions & 2 deletions monitor/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

struct timeval tp;
double current_time;
char current_jobid[80] = "0";
char jobid[80] = "0";
int nr_cpus;

int n_pmcs = 0;
Expand Down Expand Up @@ -155,7 +155,7 @@ int main(int argc, char *argv[])

gettimeofday(&tp,NULL);
current_time = tp.tv_sec+tp.tv_usec/1000000.0;
pscanf(JOBID_FILE_PATH, "%79s", current_jobid);
pscanf(JOBID_FILE_PATH, "%79s", jobid);
nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
processor = signature(&n_pmcs);

Expand Down
Loading

0 comments on commit f232cbd

Please sign in to comment.