Skip to content

Commit

Permalink
evanix: --estimate -> --statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Aug 25, 2024
1 parent 2dd578c commit f0f6eae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions include/evanix.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#ifndef EVANIX_H

struct estimate {
struct statistics {
struct sqlite3 *db;
sqlite3_stmt *statement;
};
Expand All @@ -20,7 +20,7 @@ struct evanix_opts_t {
bool check_cache_status;
bool break_evanix;
char *system;
struct estimate estimate;
struct statistics statistics;
uint32_t max_builds;
uint32_t max_time;
int (*solver)(struct job **, struct job_clist *, int32_t);
Expand Down
46 changes: 23 additions & 23 deletions src/evanix.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static const char usage[] =
" -p, --pipelined <bool> Use evanix build pipeline.\n"
" -l, --check_cache-status <bool> Perform cache locality check.\n"
" -c, --close-unused-fd <bool> Close stderr on exec.\n"
" -e, --estimate <path> Path to time estimate database.\n"
" -e, --statistics <path> Path to time statistics database.\n"
" -k, --solver sjf|conformity|highs Solver to use.\n"
"\n";

Expand All @@ -42,8 +42,8 @@ struct evanix_opts_t evanix_opts = {
.check_cache_status = true,
.solver = solver_highs,
.break_evanix = false,
.estimate.db = NULL,
.estimate.statement = NULL,
.statistics.db = NULL,
.statistics.statement = NULL,
};

static int evanix_build_thread_create(struct build_thread *build_thread);
Expand Down Expand Up @@ -140,9 +140,9 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
extern char *optarg;
int longindex, c;

const char *query = "SELECT duration "
"FROM estimate "
"WHERE estimate.pname = ? "
const char *query = "SELECT statistics.mean_duration "
"FROM statistics "
"WHERE statistics.pname = ? "
"LIMIT 1 ";

int ret = 0;
Expand All @@ -156,15 +156,15 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
{"system", required_argument, NULL, 's'},
{"solver-report", no_argument, NULL, 'r'},
{"max-time", required_argument, NULL, 't'},
{"estimate", required_argument, NULL, 'e'},
{"statistics", required_argument, NULL, 'a'},
{"pipelined", required_argument, NULL, 'p'},
{"max-builds", required_argument, NULL, 'm'},
{"close-unused-fd", required_argument, NULL, 'c'},
{"check-cache-status", required_argument, NULL, 'l'},
{NULL, 0, NULL, 0},
};

while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:e:t:", longopts,
while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:a:t:", longopts,
&longindex)) != -1) {
switch (c) {
case 'h':
Expand All @@ -186,8 +186,8 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
case 'r':
opts->solver_report = true;
break;
case 'e':
if (opts->estimate.db) {
case 'a':
if (opts->statistics.db) {
fprintf(stderr,
"option -%c can't be redefined "
"Try 'evanix --help' for more "
Expand All @@ -196,18 +196,18 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
return -EINVAL;
}

ret = sqlite3_open_v2(optarg, &opts->estimate.db,
ret = sqlite3_open_v2(optarg, &opts->statistics.db,
SQLITE_OPEN_READONLY |
SQLITE_OPEN_FULLMUTEX,
NULL);
if (ret != SQLITE_OK) {
print_err("Can't open database: %s",
sqlite3_errmsg(opts->estimate.db));
sqlite3_errmsg(opts->statistics.db));
ret = -EPERM;
goto out_free_evanix;
}
ret = sqlite3_prepare_v2(opts->estimate.db, query, -1,
&opts->estimate.statement,
ret = sqlite3_prepare_v2(opts->statistics.db, query, -1,
&opts->statistics.statement,
NULL);
if (ret != SQLITE_OK) {
print_err("%s", "Failed to prepare sql");
Expand Down Expand Up @@ -324,8 +324,8 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
"Try 'evanix --help' for more information.\n");
ret = -EINVAL;
goto out_free_evanix;
} else if (opts->max_time && !opts->estimate.db) {
fprintf(stderr, "evanix: option --max-time implies --estimate\n"
} else if (opts->max_time && !opts->statistics.db) {
fprintf(stderr, "evanix: option --max-time implies --statistics\n"
"Try 'evanix --help' for more information.\n");
ret = -EINVAL;
goto out_free_evanix;
Expand All @@ -349,20 +349,20 @@ static int evanix_free(struct evanix_opts_t *opts)
{
int ret;

if (opts->estimate.statement) {
sqlite3_finalize(opts->estimate.statement);
opts->estimate.statement = NULL;
if (opts->statistics.statement) {
sqlite3_finalize(opts->statistics.statement);
opts->statistics.statement = NULL;
}

if (opts->estimate.db) {
ret = sqlite3_close(opts->estimate.db);
if (opts->statistics.db) {
ret = sqlite3_close(opts->statistics.db);
if (ret != SQLITE_OK) {
print_err("Can't open database: %s",
sqlite3_errmsg(opts->estimate.db));
sqlite3_errmsg(opts->statistics.db));
return -EPERM;
}

opts->estimate.db = NULL;
opts->statistics.db = NULL;
}

return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,21 @@ int job_cost(struct job *job)
return -EINVAL;
}

ret = sqlite3_reset(evanix_opts.estimate.statement);
ret = sqlite3_reset(evanix_opts.statistics.statement);
if (ret != SQLITE_OK) {
print_err("%s", "Failed to reset sql statement");
ret = -EPERM;
goto out_free_pname;
}
ret = sqlite3_bind_text(evanix_opts.estimate.statement, 1, pname, -1,
ret = sqlite3_bind_text(evanix_opts.statistics.statement, 1, pname, -1,
NULL);
if (ret != SQLITE_OK) {
print_err("%s", "Failed to bind sql");
ret = -EPERM;
goto out_free_pname;
}

ret = sqlite3_step(evanix_opts.estimate.statement);
ret = sqlite3_step(evanix_opts.statistics.statement);
if (ret == SQLITE_DONE) {
print_err("Failed to acquire statistics for %s", pname);
ret = -ENOENT;
Expand All @@ -195,7 +195,7 @@ int job_cost(struct job *job)
goto out_free_pname;
}

ret = sqlite3_column_int(evanix_opts.estimate.statement, 0);
ret = sqlite3_column_int(evanix_opts.statistics.statement, 0);

out_free_pname:
free(pname);
Expand Down

0 comments on commit f0f6eae

Please sign in to comment.