Skip to content

Commit

Permalink
solver/solver_report: init
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Jul 11, 2024
1 parent ed16154 commit 3529fff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions include/evanix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct evanix_opts_t {
bool isflake;
bool isdryrun;
bool ispipelined;
bool solver_report;
bool close_unused_fd;
char *system;
uint32_t max_build;
Expand Down
1 change: 1 addition & 0 deletions include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct job {
/* solver */
ssize_t id;
bool stale;
bool reported;
};
CIRCLEQ_HEAD(job_clist, job);

Expand Down
6 changes: 6 additions & 0 deletions src/evanix.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const char usage[] =
"built.\n"
" -s, --system System to build for.\n"
" -m, --max-build Max number of builds.\n"
" -r, --solver-report Print solver report.\n"
" -p, --pipelined <bool> Use evanix build pipeline.\n"
" -c, --close-unused-fd <bool> Close stderr on exec.\n"
"\n";
Expand All @@ -27,6 +28,7 @@ struct evanix_opts_t evanix_opts = {
.isdryrun = false,
.max_build = 0,
.system = NULL,
.solver_report = false,
};

static int evanix(char *expr);
Expand Down Expand Up @@ -104,6 +106,7 @@ int main(int argc, char *argv[])
{"flake", no_argument, NULL, 'f'},
{"dry-run", no_argument, NULL, 'd'},
{"system", required_argument, NULL, 's'},
{"solver-report", no_argument, NULL, 'r'},
{"max-build", required_argument, NULL, 'm'},
{"pipelined", required_argument, NULL, 'p'},
{"close-stderr-exec", required_argument, NULL, 'c'},
Expand All @@ -126,6 +129,9 @@ int main(int argc, char *argv[])
case 's':
evanix_opts.system = optarg;
break;
case 'r':
evanix_opts.solver_report = true;
break;
case 'm':
ret = atoi(optarg);
if (ret <= 0) {
Expand Down
1 change: 1 addition & 0 deletions src/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ static int job_new(struct job **j, char *name, char *drv_path, char *attr,
job->scheduled = false;
/* unset by job_read_cache() */
job->stale = true;
job->reported = false;
job->id = -1;

job->outputs_size = 0;
Expand Down
24 changes: 0 additions & 24 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,6 @@ int queue_isempty(struct job_clist *jobs)
return true;
}

/* remove a node along with all it's ancestors recursively */
int queue_ancestors_rm(struct job *job, struct job_clist *jobs,
struct htab *htab)
{
struct job *j;
int ret;

job_stale_set(job);
CIRCLEQ_FOREACH (j, jobs, clist) {
if (j->stale == false)
continue;

ret = queue_dag_isolate(j, NULL, jobs, htab);
if (ret < 0)
return ret;

job_free(j);
/* we might have removed j->clist.cqe_next */
j = jobs->cqh_last;
}

return 0;
}

void *queue_thread_entry(void *queue_thread)
{
struct queue_thread *qt = queue_thread;
Expand Down
27 changes: 27 additions & 0 deletions src/solver_greedy.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <errno.h>
#include <queue.h>

#include "evanix.h"
#include "jobs.h"
#include "queue.h"
#include "solver_greedy.h"
Expand Down Expand Up @@ -40,6 +41,21 @@ static int32_t builds_isolated(struct job *job)
return job->deps_filled + 1;
}

static void solver_report(struct job *job, int32_t max_build)
{
if (!evanix_opts.solver_report)
return;
else if (job->reported)
return;

job->reported = true;
printf("❌ cost: %2d > %2d <-> %s -> %s\n", builds_isolated(job),
max_build, job->name, job->drv_path);

for (size_t i = 0; i < job->parents_filled; i++)
solver_report(job->parents[i], max_build);
}

int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
{
struct job *j;
Expand All @@ -53,6 +69,7 @@ int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
continue;
} else if (builds_isolated(j) > *max_build) {
job_stale_set(j);
solver_report(j, *max_build);
continue;
}
}
Expand All @@ -69,11 +86,21 @@ int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
selected->deps_filled > j->deps_filled) {
selected = j;
}

if (!evanix_opts.solver_report)
continue;
printf("ℹ️ cost: %2d, conformity: %.2f <-> %s -> %s\n",
builds_isolated(j), conformity_cur, j->name,
j->drv_path);
}

if (selected == NULL)
return -ESRCH;

if (evanix_opts.solver_report)
printf("✅ cost: %2d, conformity: %.2f <-> %s -> %s\n",
builds_isolated(selected), conformity_max,
selected->name, selected->drv_path);
*max_build -= builds_isolated(selected);
*job = selected;
return 0;
Expand Down

0 comments on commit 3529fff

Please sign in to comment.