Example #1
0
int stringize_memory_usage(ustring *u){
	uintmax_t reqd,fail;
	intmax_t used;

	pthread_mutex_lock(&memlock);
	used = allocs_used;
	reqd = allocs_reqd;
	fail = allocs_fail;
	pthread_mutex_unlock(&memlock);
	if(printUString(u,"<memstats><limit>%ju</limit>"
			"<usedtotal>%ju</usedtotal>"
			"<req>%ju</req>"
			"<failedreq>%ju</failedreq>"
			"<outstanding>%jd</outstanding>"
			"</memstats>"
			,memory_usage_limit,mem_used(),
			reqd,fail,used) < 0){
		return -1;
	}
	return 0;
}
Example #2
0
// returns 0 for failure, otherwise a scaled allocation request size
static size_t
size_palloc_req(unsigned p,const char *name){
	size_t left,reqsize;

	nag("Requested %u%% of active memory for %s\n",p,name);
	// we can't take a percentage prior to establishing free ram
	if(memory_usage_limit == 0){
		return 0;
	}
	left = memory_usage_limit - mem_used();
	nag("Memory cap details %zu bytes left\n",left);
	reqsize = left / 100;
	reqsize *= p;
	left /= 10;
	left *= 9;
	if(reqsize > left){
		reqsize = left;
		nag("%%-alloc capped at %zu bytes for sanity\n",reqsize);
	}
	return reqsize;
}
Example #3
0
static void  
free_resources (void)
{
    FILE
        *trace_f;

#if (defined (WIN32))
    mem_free (account);
    mem_free (password);
    account  = NULL;
    password = NULL;
#endif

    mem_free (application_config);
    mem_free (application_name);
    mem_free (application_version);
    mem_free (service_name);
    mem_free (service_display_name);
    mem_free (service_trace_file);
    /* resetting global variable to NULL insures there will be no problem if */
    /* free_resources is invoked more than once                              */
    application_config   = NULL;
    application_name     = NULL;
    application_version  = NULL;
    service_name         = NULL;
    service_display_name = NULL;
    service_trace_file   = NULL;

    /*  Check that all memory was cleanly released                           */
    if (mem_used ())
      {
        add_to_message_log ("Memory leak error, see 'memtrace.lst'");
        trace_f = fopen ("memtrace.lst", "w");
        if (trace_f)
          {
            mem_display (trace_f);
            fclose (trace_f);
          }
      }
}
Example #4
0
/* cover all of the lines in inflate.c up to inflate() */
local void cover_support(void)
{
    int ret;
    z_stream strm;

    mem_setup(&strm);
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);                   assert(ret == Z_OK);
    mem_used(&strm, "inflate init");
    ret = inflatePrime(&strm, 5, 31);           assert(ret == Z_OK);
    ret = inflatePrime(&strm, -1, 0);           assert(ret == Z_OK);
    ret = inflateSetDictionary(&strm, Z_NULL, 0);
                                                assert(ret == Z_STREAM_ERROR);
    ret = inflateEnd(&strm);                    assert(ret == Z_OK);
    mem_done(&strm, "prime");

    inf("63 0", "force window allocation", 0, -15, 1, Z_OK);
    inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK);
    inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK);
    inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END);
    inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR);

    mem_setup(&strm);
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
                                                assert(ret == Z_VERSION_ERROR);
    mem_done(&strm, "wrong version");

    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);                   assert(ret == Z_OK);
    ret = inflateEnd(&strm);                    assert(ret == Z_OK);
    fputs("inflate built-in memory routines\n", stderr);
}
Example #5
0
int main(void) {
    cpu_interval = 0;
    int mem_load;
    int display_mode = mode_CPU; 
    char tmp_value[20];
    mem_tot = mem_total()/1024;
    
    lcd_line("    RPi i2c test");
    lcd_line("    Copyright (C)");
    lcd_line("        2013");
    lcd_line("Jesper Stockenstrand");
    usleep(5000000);
    
    for(;;) {
        int cpu_l;
            
        switch (display_mode) {
        
            case mode_CPU:
                cpu_l = cpu_load();
                sprintf(tmp_value,"         %d%%",cpu_l);
                lcd_line("      CPU LOAD  ");
                lcd_line(tmp_value);
                lcd_line("   ");
                lcd_line(">CPU<[MEM][NET][UPT]"); 
                break;
                
            case mode_MEM:
                mem_load = (int)(((double)mem_used()/(double)mem_tot)*100);
                lcd_line("     MEM USAGE      ");
                sprintf(tmp_value,"       %d/%dMb",mem_used(),mem_tot);
                lcd_line(tmp_value);
                sprintf(tmp_value,"         %d%%",mem_load);
                lcd_line(tmp_value);
                lcd_line("[CPU]>MEM<[NET][UPT]");
                break;
                
            case mode_NET:
                lcd_line("    IP ADDRESS      ");
                sprintf(tmp_value,"    %s", net_address());
                lcd_line(tmp_value);
                lcd_line("      ");
                lcd_line("[CPU][MEM]>NET<[UPT]");
                break;
                
            case mode_UPT:
                lcd_line("       UP TIME      ");
                sprintf(tmp_value,"     %d sec",uptime());
                lcd_line(tmp_value);
                lcd_line("     ");
                lcd_line("[CPU][MEM][NET]>UPT<");
                break;
                
            default:
                display_mode = mode_CPU;
                
        }
        
        switch (checkButton()) {
        
            case 1:
                display_mode = mode_CPU;
                break;
                
            case 2:
                display_mode = mode_MEM;
                break;
                
            case 3:
                display_mode = mode_NET;
                break;
            
            case 4:
                display_mode = mode_UPT;
                break;
                
        } 

            
        usleep(10000);
    
    } 
    return(0);
}