aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-11 15:08:57 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-11 15:08:57 +0530
commit8014e99ace2a22e6b5fedfd7a381329de475c91f (patch)
tree74d569aac056fcc20261815f549619bdae07dbe0
parent3529fffd7e4e15122090bbd534c27b2f5a3a180c (diff)
job/job_cost: init
-rw-r--r--include/jobs.h1
-rw-r--r--src/jobs.c14
-rw-r--r--src/solver_greedy.c21
3 files changed, 22 insertions, 14 deletions
diff --git a/include/jobs.h b/include/jobs.h
index dc6fc36..ecf9d96 100644
--- a/include/jobs.h
+++ b/include/jobs.h
@@ -45,6 +45,7 @@ int job_read(FILE *stream, struct job **jobs);
/* Spawns nix-eval-jobs and connects its stdout to stream */
int jobs_init(FILE **stream, char *expr);
void job_free(struct job *j);
+int job_cost(struct job *job);
int job_parents_list_insert(struct job *job, struct job *parent);
void job_deps_list_rm(struct job *job, struct job *dep);
void job_stale_set(struct job *job);
diff --git a/src/jobs.c b/src/jobs.c
index 67df86f..3c17dc4 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -123,6 +123,20 @@ int job_parents_list_insert(struct job *job, struct job *parent)
return 0;
}
+int job_cost(struct job *job)
+{
+ int32_t builds = 0;
+
+ for (size_t i = 0; i < job->deps_filled; i++) {
+ if (job->deps[i]->insubstituters)
+ continue;
+
+ builds++;
+ }
+
+ return builds;
+}
+
static int job_output_insert(struct job *j, char *name, char *store_path)
{
struct output *o;
diff --git a/src/solver_greedy.c b/src/solver_greedy.c
index 0140df1..9b3e150 100644
--- a/src/solver_greedy.c
+++ b/src/solver_greedy.c
@@ -8,7 +8,6 @@
#include "util.h"
static float conformity(struct job *job);
-static int32_t builds_isolated(struct job *job);
/* conformity is a ratio between number of direct feasible derivations sharing
* dependencies of a derivation and total number of dependencies */
@@ -36,11 +35,6 @@ static float conformity(struct job *job)
return conformity;
}
-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)
@@ -49,8 +43,8 @@ static void solver_report(struct job *job, int32_t max_build)
return;
job->reported = true;
- printf("❌ cost: %2d > %2d <-> %s -> %s\n", builds_isolated(job),
- max_build, job->name, job->drv_path);
+ printf("❌ cost: %2d > %2d <-> %s -> %s\n", job_cost(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);
@@ -67,7 +61,7 @@ int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
CIRCLEQ_FOREACH (j, q, clist) {
if (j->stale) {
continue;
- } else if (builds_isolated(j) > *max_build) {
+ } else if (job_cost(j) > *max_build) {
job_stale_set(j);
solver_report(j, *max_build);
continue;
@@ -90,8 +84,7 @@ int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
if (!evanix_opts.solver_report)
continue;
printf("ℹ️ cost: %2d, conformity: %.2f <-> %s -> %s\n",
- builds_isolated(j), conformity_cur, j->name,
- j->drv_path);
+ job_cost(j), conformity_cur, j->name, j->drv_path);
}
if (selected == NULL)
@@ -99,9 +92,9 @@ int solver_greedy(struct job_clist *q, int32_t *max_build, struct job **job)
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_cost(selected), conformity_max, selected->name,
+ selected->drv_path);
+ *max_build -= job_cost(selected);
*job = selected;
return 0;
}