diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-11 13:06:42 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-11 13:06:42 +0530 |
commit | 3529fffd7e4e15122090bbd534c27b2f5a3a180c (patch) | |
tree | 15888ef5a9b567dbc46df5bb5067b7d99b7e2246 | |
parent | ed16154d1b8fed24afb32e12262210422ef99ef2 (diff) |
solver/solver_report: init
-rw-r--r-- | include/evanix.h | 1 | ||||
-rw-r--r-- | include/jobs.h | 1 | ||||
-rw-r--r-- | src/evanix.c | 6 | ||||
-rw-r--r-- | src/jobs.c | 1 | ||||
-rw-r--r-- | src/queue.c | 24 | ||||
-rw-r--r-- | src/solver_greedy.c | 27 |
6 files changed, 36 insertions, 24 deletions
diff --git a/include/evanix.h b/include/evanix.h index 1e24590..46879ad 100644 --- a/include/evanix.h +++ b/include/evanix.h @@ -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; diff --git a/include/jobs.h b/include/jobs.h index ccdff65..dc6fc36 100644 --- a/include/jobs.h +++ b/include/jobs.h @@ -28,6 +28,7 @@ struct job { /* solver */ ssize_t id; bool stale; + bool reported; }; CIRCLEQ_HEAD(job_clist, job); diff --git a/src/evanix.c b/src/evanix.c index b801e73..da2fa1a 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -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"; @@ -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); @@ -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'}, @@ -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) { @@ -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; diff --git a/src/queue.c b/src/queue.c index 4592045..049d62c 100644 --- a/src/queue.c +++ b/src/queue.c @@ -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; diff --git a/src/solver_greedy.c b/src/solver_greedy.c index d3dbb8f..0140df1 100644 --- a/src/solver_greedy.c +++ b/src/solver_greedy.c @@ -1,6 +1,7 @@ #include <errno.h> #include <queue.h> +#include "evanix.h" #include "jobs.h" #include "queue.h" #include "solver_greedy.h" @@ -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; @@ -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; } } @@ -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; |