aboutsummaryrefslogtreecommitdiff
path: root/src/jobs.c
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-08-24 20:06:12 +0530
committersinanmohd <sinan@sinanmohd.com>2024-08-24 20:23:46 +0530
commitee76b7aaf3e39fac459ac819d25b2c64c848bb3e (patch)
tree3a090a5c540a3571caae4ae6947b03859a3625ba /src/jobs.c
parent16ac10cfc0a441013229406b101fac5f02b26953 (diff)
jobs/job_cost_estimate: init
Diffstat (limited to 'src/jobs.c')
-rw-r--r--src/jobs.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/jobs.c b/src/jobs.c
index 043dac0..485a188 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <cjson/cJSON.h>
+#include <sqlite3.h>
#include "evanix.h"
#include "jobs.h"
@@ -27,6 +28,7 @@ static int job_read_inputdrvs(struct job *job, cJSON *input_drvs);
static int job_read_outputs(struct job *job, cJSON *outputs);
static int job_deps_list_insert(struct job *job, struct job *dep);
static int job_output_list_insert(struct job *job, struct output *output);
+static char *drv_path_to_pname(char *drv_path);
static void output_free(struct output *output)
{
@@ -39,6 +41,32 @@ static void output_free(struct output *output)
free(output);
}
+static char *drv_path_to_pname(char *drv_path)
+{
+ char *pname, *p;
+
+ p = strrchr(drv_path, '/');
+ if (p == NULL)
+ return NULL;
+
+ p = strchr(p, '-');
+ if (p == NULL)
+ return NULL;
+ p++;
+ if (*p == '\0')
+ return NULL;
+
+ pname = strdup(p);
+ if (pname == NULL)
+ return NULL;
+
+ p = strchr(pname, '-');
+ if (p != NULL)
+ *p = '\0';
+
+ return pname;
+}
+
static int job_output_list_insert(struct job *job, struct output *output)
{
size_t newsize;
@@ -123,6 +151,45 @@ int job_parents_list_insert(struct job *job, struct job *parent)
return 0;
}
+static int job_cost_estimate(struct job *job)
+{
+ int ret;
+ char *pname;
+
+ pname = drv_path_to_pname(job->drv_path);
+ if (pname == NULL) {
+ print_err("Unable to obtain pname from drv_path: %s",
+ job->drv_path);
+ return -EINVAL;
+ }
+
+ ret = sqlite3_bind_text(evanix_opts.estimate.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);
+ if (ret == SQLITE_DONE) {
+ ret = -ENOENT;
+ goto out_free_pname;
+ }
+ if (ret != SQLITE_ROW) {
+ print_err("%s", "Failed to step sql");
+ ret = -EPERM;
+ goto out_free_pname;
+ }
+
+ ret = sqlite3_column_int(evanix_opts.estimate.statement, 0);
+
+out_free_pname:
+ free(pname);
+
+ return ret;
+}
+
int job_cost_recursive(struct job *job)
{
int32_t builds = 1;