Skip to content

Commit

Permalink
treetop: shutdown the server when client done
Browse files Browse the repository at this point in the history
  • Loading branch information
natoscott committed Oct 4, 2024
1 parent 60291c1 commit 3114bf4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/treetop/notebooks/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,10 @@ def top_anomaly_features(self, iso, y_pred_diffi, df, N):
# use DIFFI anomaly values to find the features contributing most
rank_df = pd.DataFrame(diffi).sum().nlargest(N, keep='all')

# dictionary of keys: anomalies-feature_name and values: array of DIFFI scores
# dictionary of keys: anomalous-feature_name and values: array of DIFFI scores
frame = {}
for i in rank_df.index: # column index (original features), from ranking
key = 'anomalies-' + df.columns[i]
key = 'anomalous-' + df.columns[i]
value = [0] * df.shape[0] # zero-filled array
# fill in just the anomaly values now (replacing zeroes)
for diffi_index, value_index in enumerate(np.where(y_pred_diffi == 1)[0]):
Expand Down Expand Up @@ -1195,6 +1195,7 @@ def explain_models(self, model, train_X, train_y, test_X, test_y):

signal.signal(signal.SIGHUP, signal_refresh)
signal.signal(signal.SIGINT, signal_finished)
signal.signal(signal.SIGPIPE, signal_finished)
signal.signal(signal.SIGQUIT, signal_finished)
signal.signal(signal.SIGTERM, signal_finished)

Expand Down
10 changes: 5 additions & 5 deletions src/treetop/pcp/Feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void Feature_writeName(const Feature* fp, RichString* str) {
size_t end, n = sizeof(buffer) - 1;
const char* name = fp->name;
char* timestamp;
char* anomalies;
char* anomalous;
char* instance;

end = strlen(name);
Expand All @@ -86,8 +86,8 @@ static void Feature_writeName(const Feature* fp, RichString* str) {
n = (size_t)(timestamp - buffer) + 9;
buffer[n] = ' '; /* 1st hyphen */
}
if ((anomalies = (strstr(buffer, "anomalies-"))) != NULL) {
n = (size_t)(anomalies - buffer) + 9;
if ((anomalous = (strstr(buffer, "anomalous-"))) != NULL) {
n = (size_t)(anomalous - buffer) + 9;
buffer[n] = ' '; /* 1st hyphen */
}
instance = strchr(buffer, '[');
Expand All @@ -99,8 +99,8 @@ static void Feature_writeName(const Feature* fp, RichString* str) {
RichString_setAttrn(str, CRT_colors[DYNAMIC_GRAY], n+10, end);
}

if (anomalies) {
n = (size_t)(anomalies - buffer);
if (anomalous) {
n = (size_t)(anomalous - buffer);
RichString_setAttrn(str, shadow, n, 9);
RichString_setAttrn(str, CRT_colors[DYNAMIC_YELLOW], n+10, end);
}
Expand Down
9 changes: 7 additions & 2 deletions src/treetop/pcp/TreeTop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "pcp/TreeTop.h"

#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -198,9 +199,9 @@ bool Platform_startServer(void) {
sts = __pmProcessAddArg(&ctl, "notebooks/server.py"); /*TODO: location? */
if (sts < 0)
return false;
sts = __pmProcessExec(&ctl, PM_EXEC_TOSS_ALL, 0 /*nowait*/);
sts = __pmProcessPipe(&ctl, "r", PM_EXEC_TOSS_ALL, &pcp->server);
if (sts < 0) {
fprintf(stderr, "Cannot setup treetop server: %s\n", pmErrStr(sts));
fprintf(stderr, "Cannot start treetop server: %s\n", pmErrStr(sts));
return false;
}

Expand Down Expand Up @@ -308,8 +309,12 @@ void Platform_dynamicScreensDone(Hashtable* screens) {
}

void Platform_done(void) {
signal(SIGTERM, SIG_IGN);
killpg(0, SIGTERM);
MMV_done(pcp->map);
pmDestroyContext(pcp->context);
if (pcp->server)
__pmProcessPipeClose(pcp->server);
if (pcp->result)
pmFreeResult(pcp->result);
free(pcp->fetch);
Expand Down
1 change: 1 addition & 0 deletions src/treetop/pcp/TreeTop.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct Platform_ {
struct timeval offset; /* time offset used in archive mode only */

void* map; /* mapped memory for server communication */
FILE* server; /* process pipe file server communication */
FeatureTable* model_features; /* important metrics from the ML model */
FeatureTable* local_features; /* important SHAP metrics from sample */
FeatureTable* optim_features; /* important metrics for optimising */
Expand Down

0 comments on commit 3114bf4

Please sign in to comment.