Exemplo n.º 1
0
static int L_var_dump( lua_State* L ) 
{
    int i;
    int elements = lua_gettop( L );
    for( i = 1; i <= elements ; i++ ) 
    {
        // We need to push the last value first, because the parameters are in
        // inverted order on the stack
        lua_pushvalue( L, i );
        var_dump( L, 0 );
    }
    return 0;
}
Exemplo n.º 2
0
LIST *
var_swap(
	char	*symbol,
	LIST	*value )
{
	VARIABLE *v = var_enter( symbol );
	LIST 	 *oldvalue = v->value;

	if( DEBUG_VARSET )
	    var_dump( symbol, value, "set" );

	v->value = value;

	return oldvalue;
}
Exemplo n.º 3
0
Arquivo: debug.c Projeto: Vuzi/vuziks
// Affichage debug objet
void var_obj_dump(Object *o) {
    debug_pr_lvl(), fputs(">object\n", stdout);
    if(o) {
        debug_pr_lvl(), printf("  n_links : %d\n", o->n_links);
        debug_pr_lvl(), printf("  variables :\n");

        debug_lvl++;
        Linked_list *ll = o->ec.variables;
        while(ll)
            var_dump((Variable*)ll->value), ll = ll->next;
        debug_lvl--;

    } else
        debug_pr_lvl(), fputs("  (null)\n", stdout);
}
Exemplo n.º 4
0
LIST *
var_get( const char *symbol )
{
	VARIABLE var, *v = &var;

	v->symbol = symbol;

	if( varhash && hashcheck( varhash, (HASHDATA **)&v ) )
	{
	    if( DEBUG_VARGET )
		var_dump( v->symbol, v->value, "get" );
	    return v->value;
	}
    
	return 0;
}
Exemplo n.º 5
0
LIST * var_get( OBJECT * symbol )
{
    LIST * result = 0;
#ifdef OPT_AT_FILES
    /* Some "fixed" variables... */
    if ( strcmp( "TMPDIR", object_str( symbol ) ) == 0 )
    {
        list_free( saved_var );
        result = saved_var = list_new( L0, object_new( path_tmpdir() ) );
    }
    else if ( strcmp( "TMPNAME", object_str( symbol ) ) == 0 )
    {
        list_free( saved_var );
        result = saved_var = list_new( L0, path_tmpnam() );
    }
    else if ( strcmp( "TMPFILE", object_str( symbol ) ) == 0 )
    {
        list_free( saved_var );
        result = saved_var = list_new( L0, path_tmpfile() );
    }
    else if ( strcmp( "STDOUT", object_str( symbol ) ) == 0 )
    {
        list_free( saved_var );
        result = saved_var = list_new( L0, object_new( "STDOUT" ) );
    }
    else if ( strcmp( "STDERR", object_str( symbol ) ) == 0 )
    {
        list_free( saved_var );
        result = saved_var = list_new( L0, object_new( "STDERR" ) );
    }
    else
#endif
    {
        VARIABLE var;
        VARIABLE * v = &var;

        v->symbol = symbol;

        if ( varhash && hashcheck( varhash, (HASHDATA * *)&v ) )
        {
            if ( DEBUG_VARGET )
                var_dump( v->symbol, v->value, "get" );
            result = v->value;
        }
    }
    return result;
}
Exemplo n.º 6
0
Arquivo: debug.c Projeto: Vuzi/vuziks
void unit_cond_dump(Unit_conditional* uc) {

    Linked_list* ll = uc->statements;

    debug_pr_lvl(), puts(">conditional unit");
    debug_pr_lvl(), puts("  condition :");
        if(uc->condition) {
            debug_lvl++;
            op_dump(uc->condition);
            debug_lvl--;
        } else
            debug_pr_lvl(), puts("  (none)");



    debug_pr_lvl(), puts("  statements : ");
    debug_lvl++;

    while(ll) {
        switch(ll->type) {
            case LLT_UNIT :
                unit_dump((Unit*)(ll->value));
                break;
            case LLT_OPERATION :
                op_dump((Operation*)(ll->value));
                break;
            case LLT_VARIABLE :
                var_dump((Variable*)(ll->value));
                break;
            case LLT_CONDITION :
                unit_cond_dump((Unit_conditional*)(ll->value));
                break;
            case LLT_LOOP :
                // a faire
                break;
            default :
                debug_pr_lvl(), puts(">(error type statement)");
        }
        ll = ll->next;
    }

    debug_lvl--;

    if(uc->next)
        unit_cond_dump(uc->next);

}
Exemplo n.º 7
0
/** The watcher-list command */
int cmd_watcher_list (int argc, const char *argv[]) {
    if (OPTIONS.tenant[0] == 0) {
        fprintf (stderr, "%% No tenantid provided\n");
        return 1;
    }
    
    var *apires;
    
    if (OPTIONS.host[0]) {
        apires = api_get ("/%s/host/%s/watcher", OPTIONS.tenant, OPTIONS.host);
    }
    else {
        apires = api_get ("/%s/watcher", OPTIONS.tenant);
    }
    if (OPTIONS.json) {
        var_dump (apires, stdout);
        var_free (apires);
        return 0;
    }

    printf ("From     Meter        Trigger   Match                  "
            "Value             Weight\n"
            "-------------------------------------------------------"
            "-------------------------\n");

    var *apiwatch = var_get_dict_forkey (apires, "watcher");
    if (var_get_count (apiwatch)) {
        var *crsr = apiwatch->value.arr.first;
        while (crsr) {
            print_data (crsr->id, "warning",
                        var_get_dict_forkey (crsr, "warning"));
            print_data (crsr->id, "alert",
                        var_get_dict_forkey (crsr, "alert"));
            print_data (crsr->id, "critical",
                        var_get_dict_forkey (crsr, "critical"));
            crsr = crsr->next;
        }
        printf ("---------------------------------------------"
                "-----------------------------------\n");
    }
    var_free (apires);
    return 0;
}
Exemplo n.º 8
0
LIST *
var_get( char *symbol )
{
    LIST * result = 0;
    #ifdef OPT_AT_FILES
    /* Some "fixed" variables... */
    if ( strcmp( "TMPDIR", symbol ) == 0 )
    {
        result = list_new( L0, newstr( (char*)path_tmpdir() ) );
    }
    else if ( strcmp( "TMPNAME", symbol ) == 0 )
    {
        result = list_new( L0, newstr( (char*)path_tmpnam() ) );
    }
    else if ( strcmp( "TMPFILE", symbol ) == 0 )
    {
        result = list_new( L0, newstr( (char*)path_tmpfile() ) );
    }
    else if ( strcmp( "STDOUT", symbol ) == 0 )
    {
        result = list_new( L0, newstr( "STDOUT" ) );
    }
    else if ( strcmp( "STDERR", symbol ) == 0 )
    {
        result = list_new( L0, newstr( "STDERR" ) );
    }
    else
    #endif
    {
        VARIABLE var, *v = &var;
    
        v->symbol = symbol;
    
        if( varhash && hashcheck( varhash, (HASHDATA **)&v ) )
        {
            if( DEBUG_VARGET )
                var_dump( v->symbol, v->value, "get" );
            result = v->value;
        }
    }
    return result;
}
Exemplo n.º 9
0
/** The meter-list command */
int cmd_meter_list (int argc, const char *argv[]) {
    if (OPTIONS.tenant[0] == 0) {
        fprintf (stderr, "%% No tenantid provided\n");
        return 1;
    }
    
    var *apires = api_get ("/%s/meter", OPTIONS.tenant);
    if (OPTIONS.json) {
        var_dump (apires, stdout);
    }
    else {
        var *res_meter = var_get_dict_forkey (apires, "meter");
        if (var_get_count (res_meter)) {
            printf ("From     Meter        Type      Unit    Description\n");
            printf ("----------------------------------------"
                    "----------------------------------------\n");
            var *crsr = res_meter->value.arr.first;
            while (crsr) {
                const char *desc = var_get_str_forkey (crsr, "description");
                const char *type = var_get_str_forkey (crsr, "type");
                const char *unit = var_get_str_forkey (crsr, "unit");
                const char *org = var_get_str_forkey (crsr, "origin");
            
                if (!desc) desc = "-";
                if (!unit) unit = "";
                if (!org) org = "default";
            
                printf ("%-8s %-12s %-8s  %-7s %s\n", org, crsr->id,
                        type, unit, desc);
                crsr = crsr->next;
            }
            printf ("---------------------------------------------"
                    "-----------------------------------\n");
        }
    }
    var_free (apires);
    return 0;
}
Exemplo n.º 10
0
Arquivo: debug.c Projeto: Vuzi/vuziks
// Affichage debug d'opération
void op_dump(Operation *o) {

    debug_pr_lvl(), puts(">operation :");

    debug_pr_lvl(), printf("  type : %s (%x)\n", operation_type_debug(o->type), o->type);

    // Valeur
    if(o->identifier.s) {
        debug_pr_lvl(), printf("  info.val : %s\n", o->identifier.s ? o->identifier.s : "(null)");
        debug_pr_lvl(), printf("  info.val_h : %lu\n", (long unsigned)o->identifier.s_h);
    }
    /*if(o->info.line)
        debug_pr_lvl(), printf("  info.line : %u\n", o->info.line);*/

    // Variable
    if(o->value) {
        debug_pr_lvl(), printf("  info.value : \n");
        debug_lvl++;
        var_dump(o->value);
        debug_lvl--;
    }

    // Branches
    if(o->operations[0]) {
        debug_pr_lvl(), printf("  left operation : \n");
        debug_lvl++;
        op_dump((Operation*)o->operations[0]);
        debug_lvl--;

    }
    if(o->operations[1]) {
        debug_pr_lvl(), printf("  right operation : \n");
        debug_lvl++;
        op_dump((Operation*)o->operations[1]);
        debug_lvl--;
    }
}
Exemplo n.º 11
0
/** The get-recrod command */
int cmd_get_record (int argc, const char *argv[]) {
    if (OPTIONS.tenant[0] == 0) {
        fprintf (stderr, "%% No tenantid provided\n");
        return 1;
    }
    if (OPTIONS.host[0] == 0) {
        fprintf (stderr, "%% No hostid provided\n");
        return 1;
    }

    var *apires = api_get ("/%s/host/%s", OPTIONS.tenant, OPTIONS.host);
    
    if (OPTIONS.json) {
        var_dump (apires, stdout);
        var_free (apires);
        return 0;
    }
    
    #define Arr(x) var_get_array_forkey(apires,x)
    #define Vint(x) var_get_int_forkey(apires,x)
    #define Vstr(x) var_get_str_forkey(apires,x)
    #define Vfrac(x) var_get_double_forkey(apires,x)
    #define VDint(x,y) var_get_int_forkey(var_get_dict_forkey(apires,x),y)
    #define VDstr(x,y) var_get_str_forkey(var_get_dict_forkey(apires,x),y)
    #define VDfrac(x,y) var_get_double_forkey(var_get_dict_forkey(apires,x),y)
    #define VAfrac(x,y) var_get_double_atindex(var_get_array_forkey(apires,x),y)
    #define Vdone(x) var_delete_key(apires,x)
    /* -------------------------------------------------------------*/
    print_hdr ("HOST");
    print_value ("UUID", "%s", OPTIONS.host);
    print_value ("Hostname", "%s", Vstr("hostname"));
    print_value ("Address", "%s", VDstr("agent","ip"));
    print_value ("Status", "\033[1m%s\033[0m", Vstr("status"));
    
    print_array ("Problems", Arr("problems"));
    
    Vdone("hostname");
    Vdone("agent");
    Vdone("status");
    Vdone("problems");
    
    char uptimestr[128];
    uint64_t uptime = Vint("uptime"); Vdone("uptime");
    uint64_t u_days = uptime / 86400ULL;
    uint64_t u_hours = (uptime - (86400 * u_days)) / 3600ULL;
    uint64_t u_mins = (uptime - (86400 * u_days) - (3600 * u_hours)) / 60ULL;
    uint64_t u_sec = uptime % 60;
    
    if (u_days) {
        sprintf (uptimestr, "%llu day%s, %llu:%02llu:%02llu", u_days,
                 (u_days==1)?"":"s", u_hours, u_mins, u_sec);
    }
    else if (u_hours) {
        sprintf (uptimestr, "%llu:%02llu:%02llu", u_hours, u_mins, u_sec);
    }
    else {
        sprintf (uptimestr, "%llu minute%s, %llu second%s",
                 u_mins, (u_mins==1)?"":"s", u_sec, (u_sec==1)?"":"s");
    }
    
    print_value ("Uptime","%s",uptimestr);
    print_value ("OS/Hardware","%s %s (%s)", VDstr("os","kernel"),
                 VDstr("os","version"), VDstr("os","arch"));
    const char *dist = VDstr("os","distro");
    if (dist) print_value ("Distribution", "%s", dist);
    Vdone("os");
    
    /* -------------------------------------------------------------*/
    print_hdr ("RESOURCES");
    print_value ("Processes","\033[1m%llu\033[0m "
                             "(\033[1m%llu\033[0m running, "
                             "\033[1m%llu\033[0m stuck)",
                             VDint("proc","total"),
                             VDint("proc","run"),
                             VDint("proc","stuck"));
    Vdone("proc");
 
     print_value ("Load Average", "\033[1m%6.2f\033[0m / "
                                  "\033[1m%6.2f\033[0m / "
                                  "\033[1m%6.2f\033[0m",
                 VAfrac ("loadavg",0), VAfrac ("loadavg", 1),
                 VAfrac ("loadavg",2));
    Vdone ("loadavg");

    char cpubuf[128];
    sprintf (cpubuf, "\033[1m%6.2f \033[0m%%", Vfrac("pcpu"));
    
    char meter[32];
    strcpy (meter, "-[                      ]+");
    
    double iowait = VDfrac("io","pwait");
    double pcpu = Vfrac("pcpu"); Vdone("pcpu");
    double level = 4.5;
    
    int pos = 2;
    while (level < 100.0 && pos < 22) {
        if (level < pcpu) meter[pos++] = '#';
        else meter[pos++] = ' ';
        level += 4.5;
    }
    
    
    print_value ("CPU", "%-40s %s", cpubuf, meter);
    if (iowait>0.001) print_value ("CPU iowait", 
                                   "\033[1m%6.2f %%\033[0m", iowait);
    print_value ("Available RAM", "\033[1m%.2f\033[0m MB",
                 ((double)VDint("mem","total"))/1024.0);
    print_value ("Free RAM", "\033[1m%.2f\033[0m MB",
                 ((double)VDint("mem","free"))/1024.0);
    
    print_value ("Network in/out", "\033[1m%i\033[0m Kb/s "
                                   "(\033[1m%i\033[0m pps) / "
                                   "\033[1m%i\033[0m Kb/s "
                                   "(\033[1m%i\033[0m pps)",
                                   VDint("net","in_kbs"),
                                   VDint("net","in_pps"),
                                   VDint("net","out_kbs"),
                                   VDint("net","out_pps"));
    
    print_value ("Disk i/o", "\033[1m%i\033[0m rdops / "
                             "\033[1m%i\033[0m wrops",
                 VDint("io","rdops"), VDint("io","wrops"));
    
    Vdone("mem");
    Vdone("net");
    Vdone("io");
    Vdone("badness");

    print_values (apires, NULL);
    
    /* -------------------------------------------------------------*/
    print_hdr ("PROCESS LIST");
    
    const char *top_hdr[] = {"USER","PID","CPU","MEM","NAME",NULL};
    const char *top_fld[] = {"user","pid","pcpu","pmem","name",NULL};
    columnalign top_align[] = {CA_L, CA_R, CA_R, CA_R, CA_L, CA_NULL};
    vartype top_tp[] =
        {VAR_STR,VAR_INT,VAR_DOUBLE,VAR_DOUBLE,VAR_STR,VAR_NULL};
    int top_wid[] = {15, 7, 9, 9, 0, 0};
    int top_div[] = {0, 0, 0, 0, 0, 0};
    const char *top_suf[] = {"",""," %", " %", "", NULL};
    
    var *v_top = var_get_array_forkey (apires, "top");
    print_table (v_top, top_hdr, top_fld, 
                 top_align, top_tp, top_wid, top_suf, top_div);
    
    Vdone("top");
    /* -------------------------------------------------------------*/
    print_hdr ("STORAGE");
    
    const char *df_hdr[] = {"DEVICE","SIZE","FS","USED","MOUNTPOINT",NULL};
    const char *df_fld[] = {"device","size","fs","pused","mount",NULL};
    columnalign df_aln[] = {CA_L,CA_R,CA_L,CA_R,CA_L,CA_NULL};
    vartype df_tp[] = {VAR_STR,VAR_INT,VAR_STR,VAR_DOUBLE,VAR_STR,VAR_NULL};
    int df_wid[] = {12, 14, 6, 8, 0};
    int df_div[] = {0, (1024), 0, 0, 0, 0};
    const char *df_suf[] = {""," GB", "", " %", "", ""};
    
    var *v_df = var_get_array_forkey (apires, "df");
    
    /*print_generic_table (v_df);*/
    
    print_table (v_df, df_hdr, df_fld,
                 df_aln, df_tp, df_wid, df_suf, df_div);
    
    Vdone("df");
    
    /** Print any remaining table data */
    print_tables (apires);
        
    printf ("---------------------------------------------"
            "-----------------------------------\n");

    var_free (apires);
    print_done();
    return 0;    
}
Exemplo n.º 12
0
LIST * var_get( struct module_t * module, OBJECT * symbol )
{
    LIST * result = L0;
#ifdef OPT_AT_FILES
    /* Some "fixed" variables... */
    if ( object_equal( symbol, constant_TMPDIR ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_new( path_tmpdir()->value ) );
    }
    else if ( object_equal( symbol, constant_TMPNAME ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( path_tmpnam() );
    }
    else if ( object_equal( symbol, constant_TMPFILE ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( path_tmpfile() );
    }
    else if ( object_equal( symbol, constant_STDOUT ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_copy( constant_STDOUT ) );
    }
    else if ( object_equal( symbol, constant_STDERR ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_copy( constant_STDERR ) );
    }
    else
#endif
    {
        VARIABLE * v;
        int n;

        if ( ( n = module_get_fixed_var( module, symbol ) ) != -1 )
        {
            if ( DEBUG_VARGET )
                var_dump( symbol, module->fixed_variables[ n ], "get" );
            result = module->fixed_variables[ n ];
        }
        else if ( module->variables && ( v = (VARIABLE *)hash_find(
            module->variables, symbol ) ) )
        {
            if ( DEBUG_VARGET )
                var_dump( v->symbol, v->value, "get" );
            result = v->value;
        }

#ifdef OS_VMS
        else if ( ( module->name && object_equal( module->name, constant_ENVIRON ) )
                  || root_module() == module )
        {
            /* On VMS, when a variable from root or ENVIRON module is not found,
             * explicitly request it from the process.
             * By design, process variables (and logicals) are not made available
             * to C main(), and thus will not get loaded in bulk to root/ENVRON.
             * So we get around it by getting any such variable on first request.
             */
            const char * val = getenv( object_str( symbol ) );

            if ( val )
            {
                struct module_t * environ_module = module;
                char * environ[ 2 ] = { 0 }; /* NULL-terminated */
                string buf[ 1 ];

                if ( root_module() == module )
                {
                    environ_module = bindmodule( constant_ENVIRON );
                }

                string_copy( buf, object_str( symbol ) );
                string_append( buf, "=" );
                string_append( buf, val );

                environ[ 0 ] = buf->value;

                /* Load variable to global module, with splitting, for backward
                 * compatibility. Then to .ENVIRON, without splitting.
                 */
                var_defines( root_module(), environ, 1 );
                var_defines( environ_module, environ, 0 );
                string_free( buf );

                if ( module->variables && ( v = (VARIABLE *)hash_find(
                    module->variables, symbol ) ) )
                {
                    if ( DEBUG_VARGET )
                        var_dump( v->symbol, v->value, "get" );
                    result = v->value;
                }
            }
        }
#endif
    }
    return result;
}
Exemplo n.º 13
0
static void var_dump( lua_State* L, int depth ) 
{
    // All the different datatypes need to be handled differently
    if ( lua_isnil( L, -1 ) ) 
    {
        print_padded_line( depth, "NIL" );
    }
    else if ( lua_isfunction( L, -1 ) ) 
    {
        print_padded_line( depth, "FUNCTION" );
    }
    else if ( lua_isuserdata( L, -1 ) ) 
    {
        print_padded_line( depth, "USERDATA" );
    }
    else if ( lua_isthread( L, -1 ) ) 
    {
        print_padded_line( depth, "THREAD" );
    }
    else if ( lua_isboolean( L, -1 ) ) 
    {        
        print_padded_line( depth, "boolean(%s)", lua_toboolean( L, -1 ) == true ? "true" : "false" );
    }
    else if ( lua_isnumber( L, -1 ) )
    {
        double number = lua_tonumber( L, -1 );

        if ( (double)(int)number == number ) 
        {
            print_padded_line( depth, "integer(%i)", (int)number );
        }
        else
        {
            print_padded_line( depth, "float(%f)", number );
        }
    }
    else if( lua_isstring( L, -1 ) ) 
    {
        print_padded_line( depth, "string(%d) \"%s\"", lua_strlen( L, -1 ), lua_tostring( L, -1 ) );
    }
    else if( lua_istable( L, -1 ) ) 
    {
        print_padded_line( depth, "table(%i) {", lua_objlen( L, -1 ) );

        // Push nil as first key before calling next
        lua_pushnil( L );
        while ( lua_next(L, -2 ) != 0 ) {            
            if ( lua_isnumber( L, -2 ) ) 
            {
                print_padded_line( depth + 1, "[%i] =>", lua_tointeger( L, -2 ) );
            }
            else
            {
                print_padded_line( depth + 1, "[\"%s\"] =>", lua_tostring( L, -2 ) );                
            }
            var_dump( L, depth + 1 );
        }
        print_padded_line( depth, "}" );
    }

    lua_pop( L, 1 );
}