Alien-libhisto

 view release on metacpan or  search on metacpan

bundled/include/histo/cli.h  view on Meta::CPAN

#endif

/**
 * @brief Top-level multi-call CLI dispatcher (histo / phisto).
 *
 * Dispatches to subcommands: fill, plot, stats, fit, cmp.
 *
 * @param argc Argument count.
 * @param argv Argument vector.
 * @param out Output stream for normal emission (e.g. stdout).
 * @param err Error stream for diagnostics and logging (e.g. stderr).
 * @return 0 on success, non-zero exit status code on error.
 */
int histo_cli_main(int argc, char **argv, FILE *out, FILE *err);

/**
 * @brief CLI streaming ingestion and aggregation tool (histo-fill).
 *
 * @param argc Argument count.
 * @param argv Argument vector.
 * @param out Output stream for serialized histogram (binary, JSON, or summary).

bundled/tools/scripts/test_container.py  view on Meta::CPAN



def test_engine_connectivity(engine):
    """Test if container engine binary exists and can communicate with daemon/socket."""
    if not shutil.which(engine):
        return False, f"'{engine}' binary not found in PATH", False
    try:
        res = subprocess.run(
            [engine, "info"],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.PIPE,
            text=True,
            timeout=10
        )
        if res.returncode == 0:
            return True, "", False
        if engine == "docker" and shutil.which("sg") and "permission denied" in res.stderr.lower():
            sg_res = subprocess.run(
                ["sg", "docker", "-c", f"{engine} info"],
                stdout=subprocess.DEVNULL,
                stderr=subprocess.PIPE,
                text=True,
                timeout=10
            )
            if sg_res.returncode == 0:
                return True, "", True
        return False, res.stderr.strip(), False
    except Exception as e:
        return False, str(e), False


def detect_container_engine(preferred="auto"):
    """Detect an available and working container engine (docker or podman)."""
    global USE_SG_DOCKER
    candidates = ["docker", "podman"] if preferred == "auto" else [preferred]
    errors = {}

bundled/tools/scripts/test_container.py  view on Meta::CPAN

    binfmt_path = Path("/proc/sys/fs/binfmt_misc")
    if binfmt_path.exists():
        entries = list(binfmt_path.iterdir())
        has_qemu = any("qemu-" in e.name for e in entries)
        if has_qemu:
            return

    log("Registering QEMU user-mode binfmt handlers via multiarch/qemu-user-static...")
    try:
        cmd = [engine, "run", "--rm", "--privileged", "multiarch/qemu-user-static", "--reset", "-p", "yes"]
        exec_container_cmd(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
    except Exception as e:
        log_error(f"Warning: Failed to auto-register binfmt handlers ({e}). Foreign architectures may fail if not pre-configured.")


def run_native_32bit(repo_root, jobs, build_type="Release", full=False):
    """Run native 32-bit test on host using -m32 flags."""
    build_dir = repo_root / "build-x86_32"
    log(f"Running Host Native 32-bit Build & Test in {build_dir}...")

    cmake_args = [

bundled/tools/scripts/test_container.py  view on Meta::CPAN


    if args.clean:
        log("Cleaning container build directories...")
        for p in repo_root.glob("build-container-*"):
            if p.is_dir():
                shutil.rmtree(p, ignore_errors=True)
                if p.is_dir():
                    engine = detect_container_engine()
                    if engine:
                        try:
                            exec_container_cmd([engine, "run", "--rm", "-v", f"{repo_root}:/workspace", "alpine:latest", "rm", "-rf", f"/workspace/{p.name}"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
                        except Exception:
                            pass
        if (repo_root / "build-x86_32").is_dir():
            shutil.rmtree(repo_root / "build-x86_32", ignore_errors=True)
        log_success("Clean complete.")
        return 0

    # Resolve target
    target_key = args.target.lower()
    target_key = ALIASES.get(target_key, target_key)

bundled/tools/src/cli_main.c  view on Meta::CPAN

    fprintf(out, "  cmp      Compare two histograms and compute statistical distance metrics\n");
    fprintf(out, "  top      Interactive terminal monitor for live 1D/2D data streams\n\n");
    fprintf(out, "Flags:\n");
    fprintf(out, "  -h, --help       Show this help message\n");
    fprintf(out, "  -v, --version    Show version information\n\n");
    fprintf(out, "For command-specific help, run: %s <command> --help\n", prog);
}

int histo_cli_main(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;
    if (argc < 1) return 1;

    /* Check if invoked directly via symlink (e.g. histo-fill, histo_plot, phisto-fill) */
    const char *prog_name = argv[0];
    const char *slash = strrchr(prog_name, '/');
    if (slash) prog_name = slash + 1;

    if (strcmp(prog_name, "histo-fill") == 0 || strcmp(prog_name, "histo_fill") == 0 ||
        strcmp(prog_name, "phisto-fill") == 0) {
        return histo_cli_fill(argc, argv, out, err);

bundled/tools/src/cmd_cmp.c  view on Meta::CPAN

#include "cli_common.h"
#include "cli_opt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int histo_cli_cmp(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;

    const char *fmt = "table";

    const cli_opt_spec_t specs[] = {
        {'f', "format", NULL, CLI_OPT_TYPE_STRING, &fmt, NULL, 0, "FMT",
         "Output format: table (default), json, tsv", "table"}
    };

    cli_opt_parser_t parser;
    cli_opt_init(&parser, specs, sizeof(specs) / sizeof(specs[0]),

bundled/tools/src/cmd_fill.c  view on Meta::CPAN

        ctx->var_edges[ctx->n_edges++] = strtod(p, &endp);
        if (endp == p) break;
        if (*endp == ',') p = endp + 1;
        else p = endp;
    }
    return 0;
}

int histo_cli_fill(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;

    bool is_2d = false;
    uint32_t nbins = 50;
    double range_min = NAN, range_max = NAN;
    bool auto_range = false;
    const char *auto_bins_rule_str = NULL;
    int auto_bins_rule = -1;

    uint32_t xbins = 0, ybins = 0;
    double xmin = NAN, xmax = NAN, ymin = NAN, ymax = NAN;

bundled/tools/src/cmd_fill.c  view on Meta::CPAN

        size_t count_2d = 0, cap_2d = 0;
        bool auto_range_2d = (!has_xmin || !has_xmax || !has_ymin || !has_ymax || auto_range);
        uint64_t sample_count_2d = 0;
        double last_emit_time_2d = cli_get_time_sec();


        histo2d_t *h2 = NULL;
        if (!auto_range_2d) {
            h2 = histo2d_create_uniform(xbins, xmin, xmax, ybins, ymin, ymax, flags);
            if (!h2) {
                fprintf(stderr, "Error: Failed to initialize 2D histogram.\n");
                if (out_fp != stdout) fclose(out_fp);
                return 1;
            }
        }

        for (int f = 0; f < nfiles; ++f) {
            FILE *in_fp = strcmp(files[f], "-") == 0 ? stdin : fopen(files[f], "r");
            if (!in_fp) {
                fprintf(stderr, "Warning: Cannot open input file '%s'\n", files[f]);
                continue;
            }

            char line[4096];
            char detected_delim = delim;

            while (fgets(line, sizeof(line), in_fp)) {
                char *p = line;
                while (*p && isspace((unsigned char)*p)) p++;
                if (*p == '\0' || *p == '#') continue;

bundled/tools/src/cmd_fill.c  view on Meta::CPAN

        if (var_edges && n_edges >= 2) {
            h = histo_create_variable((uint32_t)(n_edges - 1), var_edges, flags);
        } else {
            if (range_min >= range_max) {
                range_min = 0.0;
                range_max = 100.0;
            }
            h = histo_create_uniform(nbins, range_min, range_max, flags);
        }
        if (!h) {
            fprintf(stderr, "Error: Failed to initialize histogram.\n");
            if (var_edges) free(var_edges);
            if (out_fp != stdout) fclose(out_fp);
            cli_opt_free(&parser);
            return 1;
        }
    }

    uint64_t sample_count = 0;
    double last_emit_time = cli_get_time_sec();

    for (int f = 0; f < nfiles; ++f) {
        FILE *in_fp = NULL;
        if (strcmp(files[f], "-") == 0) {
            in_fp = stdin;
        } else {
            in_fp = fopen(files[f], binary_input || merge_mode ? "rb" : "r");
            if (!in_fp) {
                fprintf(stderr, "Warning: Cannot open input file '%s'\n", files[f]);
                continue;
            }
        }

        if (merge_mode) {
            histo_t *incoming = NULL;
            while (cli_read_histogram_from_stream(in_fp, &incoming) == HISTO_OK) {
                if (!h) {
                    h = incoming;
                } else {

bundled/tools/src/cmd_fit.c  view on Meta::CPAN

    fit_bounds_ctx_t *ctx = (fit_bounds_ctx_t *)data;
    if (!val || sscanf(val, "%lf:%lf", &ctx->range_min, &ctx->range_max) != 2) {
        snprintf(err_buf, err_size, "Range must be in MIN:MAX format (e.g. --range=0:100)");
        return 1;
    }
    return 0;
}

int histo_cli_fit(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;

    const char *model_str = "gaussian";
    uint32_t poly_degree = 1;
    bool use_mle = false;
    bool use_unweighted = false;
    double confidence = 0.95;
    bool do_json = false;
    bool do_quiet = false;
    bool do_plot = false;
    const char *input_file = NULL;

bundled/tools/src/cmd_plot.c  view on Meta::CPAN

        render_histogram_sparkline(h, style, use_color, palette, log_scale, show_stats, out);
    } else {
        render_histogram_console(h, term_width, style, use_color, palette, log_scale, show_errors, show_stats, title, out);
    }
}

#include "cli_opt.h"

int histo_cli_plot(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;

    int term_width = cli_get_terminal_width(80);
    const char *style = "blocks";
    const char *color_mode = "auto";
    const char *palette_name = NULL;
    histo_palette_t palette = HISTO_PALETTE_VIRIDIS;
    bool log_scale = false;
    bool show_errors = false;
    bool show_stats = true;
    bool sparkline = false;

bundled/tools/src/cmd_stats.c  view on Meta::CPAN

        fprintf(out, "  Bivariate Correlation & Covariance:\n");
        fprintf(out, "    Covariance:     %-12.6g Pearson (rho): %.6f\n", s.covariance, s.correlation);
        fprintf(out, "===============================================================\n");
    }
}

#include "cli_opt.h"

int histo_cli_stats(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;

    const char *fmt = "table";
    bool all_metrics = true;

    const cli_opt_spec_t specs[] = {
        {'f', "format", NULL, CLI_OPT_TYPE_STRING, &fmt, NULL, 0, "FMT",
         "Output format: table (default), json, tsv", "table"},
        {'a', "all", NULL, CLI_OPT_TYPE_BOOL, &all_metrics, NULL, 0, NULL,
         "Compute all extended higher moments and peak metrics", NULL}
    };

bundled/tools/src/cmd_top.c  view on Meta::CPAN

        eng->running = false;
    }
}



#include "cli_opt.h"

int histo_cli_top(int argc, char **argv, FILE *out, FILE *err) {
    if (!out) out = stdout;
    if (!err) err = stderr;
    (void)out;
    bool is_2d = false;
    uint32_t nbins = 50;
    uint32_t xbins = 0, ybins = 0;
    double rmin = 0.0, rmax = 100.0;
    double xmin = NAN, xmax = NAN;
    double ymin = NAN, ymax = NAN;
    bool auto_range = true;
    bool no_autorange = false;
    double auto_range_threshold = 0.05;

bundled/tools/src/main.c  view on Meta::CPAN

/*
 * Executable main entrypoint dispatching to the libhistocli command runner.
 */

#include "histo/cli.h"
#include <stdio.h>

int main(int argc, char **argv) {
    return histo_cli_main(argc, argv, stdout, stderr);
}



( run in 1.109 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )