Beispiel #1
0
int main(int argc, char **argv)
{
    int i = 0, id = 0, n = 0, x = 0, count = 50000000;
    char line[FILE_LINE_MAX], *p = NULL;
    unsigned short *list = NULL;
    unsigned char digest[MD5_LEN];
    MMKEY *mmkey = NULL;
    void *timer = NULL;

    if((mmkey = mmkey_init("/tmp/test.mmkey")))
    {
        TIMER_INIT(timer);
        for(i = 1; i <= count; i++)
        {
            n = sprintf(line, "http://www.demo.com/%d.html", i);
            md5(line, n, digest);
            list = (unsigned short *)digest;
            id = mmkey_xadd(mmkey, list, 4);
            /*
            if(mmkey_get(mmkey, list, 4) != i)
            {
                fprintf(stderr, "NoFound key:%02X%02X%02X%02X id:%d\n", list[0],list[1],list[2],list[3], i);
                _exit(-1);
            }
            */
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "%s::%d insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer));
        TIMER_CLEAN(timer);
        mmkey->clean(mmkey);
    }
}
Beispiel #2
0
/********************************************************************************
 *  Name                 :	Sch_Init
 *  Description          :	Scheduler's initialization function.
 *  Parameters           :  void
 *  Return               :	void
 *  Critical/explanation :  This routine prepares the scheduler to run. 
 							Initializes the Task Control Block according to the
 							number of configured tasks, suding a memory allocation algorithm,
 							marking all tasks as SUSPENDED.
 							Configures the timer used as the system's tick.
 							Sets the scheduler's counter to 0 and its status to INITIALIZED.
 ********************************************************************************/
 void Sch_Init(const S_SCH_CONFIG *lps_SchConfig_Init){
 	T_UBYTE lub_i_Init;
	T_UBYTE lub_NumberOfTasks_Init;
	
 	S_TASK_DESCRIPTOR * lp_TaskDescriptorPtr_Init; 
 	rps_SchConfig_ptr = lps_SchConfig_Init;
 	
 	lp_TaskDescriptorPtr_Init = (S_TASK_DESCRIPTOR *)(lps_SchConfig_Init->SchTaskDescriptor);
 	lub_NumberOfTasks_Init = lps_SchConfig_Init->SchNumberOfTasks;
 	
 	ras_SchTaskControlBlock_ptr = (S_SCH_TASK_CONTROL*)MemAlloc(sizeof(S_SCH_TASK_CONTROL)*lub_NumberOfTasks_Init);
 	
 	for(lub_i_Init=0; lub_i_Init<lub_NumberOfTasks_Init; lub_i_Init++){
 		
 		/* Set all tasks to SUSPENDED */
 		ras_SchTaskControlBlock_ptr[lub_i_Init].SchTaskState = TASK_STATE_SUSPENDED;
 		ras_SchTaskControlBlock_ptr[lub_i_Init].TaskFunctionControlPtr = lp_TaskDescriptorPtr_Init->TaskFunctionPtr;
 		lp_TaskDescriptorPtr_Init++;
 	}
  	
    TIMER_LOAD_VALUE_CYCLES(39999U,0); /* 625 us to cycles */
    TIMER_ENABLE_INT(0);
    TIMER_INIT();
  	
 	rs_SchControl.SchCounter = 0;
 	rs_SchControl.SchStatus = SCH_INIT;
 }
Beispiel #3
0
/* http request */
int http_request(CONN *conn)
{
    char *p = NULL, path[HTTP_PATH_MAX], buf[HTTP_BUF_SIZE];
    int n = 0;

    if(running_status && conn)
    {
        //fprintf(stdout, "%s::%d conn[%d]->status:%d\n", __FILE__, __LINE__, conn->fd, conn->status);
        if(nrequests >= ntasks)
        {
            return -1;
        }
        if(nrequests == 0)
        {
            TIMER_INIT(timer);
        }
        ++nrequests;
        conn->start_cstate(conn);
        conn->set_timeout(conn, req_timeout);
        if(fp && fgets(path, HTTP_PATH_MAX, fp))
        {
            //fprintf(stdout, "%s::%d conn[%s:%d][%d]->status:%d\n", __FILE__, __LINE__, conn->local_ip, conn->local_port, conn->fd, conn->status);
            p = path;
            while(*p != '\0' && *p != '\n' && *p != '\r')++p;
            *p = '\0';
            if(is_post)
            {
                p = buf;
                p += sprintf(p, "POST /%s HTTP/1.1\r\n", path);
                p += sprintf(p, "Host: %s:%d\r\n", server_host, server_port);
                if(is_keepalive) p += sprintf(p, "Connection: KeepAlive\r\n");
                p += sprintf(p, "Content-Length: %d\r\n\r\n", (int)strlen(server_argv));
                p += sprintf(p, "\r\n");
                if(strlen(server_argv) > 0) p += sprintf(p, "%s", server_argv);
                n = p - buf;
            }
            else
            {
                p = buf;
                if(strlen(server_argv) > 0) 
                    p += sprintf(p, "GET /%s?%s HTTP/1.1\r\n", path, server_argv);
                else 
                    p += sprintf(p, "GET /%s HTTP/1.1\r\n", path);
                p += sprintf(p, "Host: %s:%d\r\n", server_host, server_port);
                if(is_keepalive) p += sprintf(p, "Connection: KeepAlive\r\n");
                p += sprintf(p, "\r\n");
                n = p - buf;
            }
            if(is_verbosity && is_quiet == 0) fprintf(stdout, "%s", buf);
            conn->save_cache(conn, path, strlen(path)+1);
            return conn->push_chunk(conn, buf, n);
        }
        else
        {
            return conn->push_chunk(conn, request, request_len);
        }
    }
    return -1;
}
Beispiel #4
0
int main()
{
    int i = 0, key = 0, count = 10000, ret = 0;
    void *map = NULL, *timer = NULL;

    if((map = IMMX_INIT()))
    {
        TIMER_INIT(timer);
        while(i++ < count)
        {
            key = random()%count;
            IMMX_ADD(map, key);
            //if(olddp)fprintf(stdout, "old[%d:%08x]\n", key, olddp);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "insert %d nodes count:%d free:%d total:%d time used:%lld\n", count,  PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer));
        i = 0;
        while(i++ < count)
        {
            key = random()%count;
            ret = 0;
            IMMX_GET(map, key, ret);
            if(ret) fprintf(stdout, "%d:[%d]\n", key, ret);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "get %d nodes count:%d free:%d total:%d time used:%lld\n", count,  PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer));
        do
        {
            ret = 0;
            IMMX_POP_MIN(map, key, ret);
            if(ret) fprintf(stdout, "%d:[%d]\n", key, ret); 
        }while(IMX_ROOT(map));
        TIMER_SAMPLE(timer);
        fprintf(stdout, "pop min(%d) node count:%d free:%d total:%d time used:%lld\n", count,  PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer));
        i = 0;
        while(i < count)
        {
            key = random()%count;
            IMMX_ADD(map, key);
            ++i;
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "insert %d nodes count:%d free:%d total:%d time used:%lld\n", count,  PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer));
        do
        {
            ret = 0;
            IMMX_POP_MAX(map, key, ret);
            if(ret) fprintf(stdout, "%d:[%d]\n", key, ret); 
        }while(IMX_ROOT(map));
        TIMER_SAMPLE(timer);
        fprintf(stdout, "pop max(%d) nodes count:%d free:%d total:%d time used:%lld\n", count,  PIMX(map)->count, PIMX(map)->free_count, PIMX(map)->total, PT_LU_USEC(timer));
        TIMER_SAMPLE(timer);
        TIMER_CLEAN(timer);
        IMMX_CLEAN(map);
    }
}
Beispiel #5
0
// ----------------------------------------------------------------------------
// Инициализация - обнуление состояний, запуск аппаратного таймера
void BSP_timer_init(void) 
{
    uint8_t i;
    for (i = 0; i < SWTIMERS_MAX; i++) {
        swTimers[i].is_stopped = 1; 
    }
    
    // Запуск аппаратного таймера
    TIMER_INIT();
}
Beispiel #6
0
/**
* @brief Initialization of the timer module
*/
void timer_init(void)
{
    TIMER_INIT();
#   ifdef HAVE_MALLOC_TIMERS
    memset(timer_pool, 0,
           sizeof(timer_t)*TIMER_POOL_SIZE);
#   endif
    tqhead = NULL;
    systime = 0;
}
Beispiel #7
0
void Timer_Initialize(uint32_t timer, uint32_t time_us)
{
    uint32_t reload = 0;

    if (timer < NUM_TIMERS)
    {
        if (time_us == 0)
            reload = TIMER_MAX_VALUE;
        else
            reload = (time_us) * TIMER_TICKS_US;

        switch(timer) {
            case 0: TIMER_INIT(0, reload);
                    break;
            case 1: TIMER_INIT(1, reload);
                    break;
            default: break;
        }
    }
}
void BuildsWindow::Update() {
	if (!queue.empty() && TIMER_DIFF(send_timer) > 600) {
		if (GW::Map::GetInstanceType() != GW::Constants::InstanceType::Loading
			&& GW::Agents::GetPlayer()) {

			send_timer = TIMER_INIT();
			GW::Chat::SendChat('#', queue.front().c_str());
			queue.pop();
		}
	}
}
Beispiel #9
0
/**
     Initialize the MAC timer.  Called at powerup, or when you
   want to clear all timers.  Sets the timeout for each tick of the
   system clock.
 */
void timerInit(void)
{
    TIMER_INIT();

    // Init the PRNG
    if (NODE_TYPE == ROUTER || NODE_TYPE == COORD)
        srand(TCNT(TICKTIMER));

	TIMER_CLEAR();

    // Enable timer output compare interrupt.  -- Timer starts to interrupt as soon as Global interrup is enabled
    TIMER_ENABLE();
}
Beispiel #10
0
/*
 * Device Attach
 */
struct ath_cwm *
cwm_attach(void *wlandev, osdev_t osdev, struct ath_cwm_conf *cwm_conf_parm)
{
    struct ath_cwm *cw_struct;

    CWM_DBG_PRINT(wlandev, "%s\n", __func__);

    cw_struct = (struct ath_cwm *)CWM_ALLOC_STATE_STRUCT(osdev,
                sizeof(struct ath_cwm));
    if (cw_struct == NULL) {
        CWM_DBG_PRINT(wlandev, "%s: no memory for cwm attach\n", __func__);
        return NULL;
    }

    OS_MEMZERO(cw_struct, sizeof(struct ath_cwm));

    /* Init OS hdl and WLAN dev hdl */
    cw_struct->osdev = osdev;
    cw_struct->wlandev = wlandev;

    /* ieee80211 Layer - Default Configuration */
    cw_struct->cw_mode 		= CWM_MODE20;
    cw_struct->cw_extoffset 	= 0;
    cw_struct->cw_extprotmode	= CWM_EXTPROTNONE;
    cw_struct->cw_extprotspacing 	= CWM_HT_EXTPROTSPACING_25;
    cw_struct->cw_enable      	= cwm_conf_parm->cw_enable;
    cw_struct->cw_extbusythreshold = ATH_CWM_EXTCH_BUSY_THRESHOLD;
    cw_struct->cw_width = CWM_WIDTH20;
    cw_struct->cw_ht40allowed = 1;

    /* Allocate resources */
    TIMER_INIT(osdev, &cw_struct->ac_timer,
               CWM_timer_fn_ptr, cw_struct);
    spin_lock_init(&cw_struct->ac_lock);
    TAILQ_INIT(&cw_struct->ac_eventq);

    /* Atheros layer initialization */
    cw_struct->ac_running 	= 0;
    cw_struct->ac_timer_statetime = 0;
    cw_struct->ac_timer_prevstate = ATH_CWM_STATE_EXT_CLEAR;
    cw_struct->ac_vextch 		= 0;
    cw_struct->ac_vextchbusy 	= 0;
    cw_struct->ac_extchbusyper 	= 0;

    /* default state */
    cw_struct->ac_state  		= ATH_CWM_STATE_EXT_CLEAR;
    CWM_inithwstate(cw_struct);

    return cw_struct;
}
Beispiel #11
0
void
view_glx_render(struct view* view)
{
    TIMER_INIT();
    TIMER_START();
    
    view_render(view);
        
    glXSwapBuffers(view->glx_display, view->glx_window);
    
    TIMER_STOP_PRINT("View: GlxRender");
    
    usleep(1000);
}
Beispiel #12
0
int main(int argc, char **argv) 
{
    int i = 0, rootid = 0, id = 0, j = 0, old = 0, data = 0, n = 0, count = 50000000;
    unsigned char digest[MD5_LEN];
    void *mmtree = NULL;
    void *timer = NULL;
    char line[1024];
    int64_t key = 0;

    if((mmtree = mmtree64_init("/tmp/test.mmtree64")))
    {
        rootid = mmtree64_new_tree(mmtree);
        TIMER_INIT(timer);
        for(j = 1; j <= count; j++)
        {
            n = sprintf(line, "http://www.demo.com/%d.html", j);
            md5(line, n, digest);
            key = *((int64_t *)digest);
            old = -1;
            data = j;
            id = mmtree64_insert(mmtree, rootid, key, data, &old);
            if(old > 0 || id <= 0) 
            {
                fprintf(stdout, "%d:{id:%d key:%d rootid:%d old:%d}\n", j, id, key, rootid, old);
            }
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "%s::%d insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer));
        for(j = 1; j <= count; j++)
        {
            n = sprintf(line, "http://www.demo.com/%d.html", j);
            md5(line, n, digest);
            key = *((int64_t *)digest);
            old = -1;
            data = j;
            id = mmtree64_try_insert(mmtree, rootid, key, data, &old);
            if(old > 0 && old != j) 
            {
                fprintf(stdout, "%d:{id:%d key:%d rootid:%d old:%d}\n", j, id, key, rootid, old);
                _exit(-1);
            }
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "%s::%d try_insert:%d time:%lld\n", __FILE__,__LINE__, count, PT_LU_USEC(timer));
        TIMER_CLEAN(timer);
        mmtree64_close(mmtree);
    }
}
Beispiel #13
0
//--------------------------------------------------------------------------
Server::Server(const VeChar8* pcName, const VeChar8* pcConfigPath)
	: PropertySContainer(this), m_kName(pcName), m_pkPeer(NULL), m_kAgentMap(1024), m_kDatabase(NULL)
	, m_strServerName(this, FLAG_DATABASE, "ServerName", pcName)
	, m_u64ServerTime(this, FLAG_DATABASE, "ServerTime", 0)
{
	m_kNode.m_tContent = this;
	g_pServerManager->AddServer(pcName, this);
	m_pkPeer = VEPeerInterface::GetInstance();

	VeChar8 acBuffer[64];
	VeSprintf(acBuffer, 64, "%s.xml", pcName);
	VeDirectory* pkDir = g_pResourceManager->CreateDir(pcConfigPath);
	VeBinaryIStreamPtr spConfig = pkDir->OpenSync(acBuffer);
	(*spConfig) >> m_kConfig;
	g_pResourceManager->DestoryDir(pkDir);

	TIMER_INIT(Server, _SyncToDatabase);
}
Beispiel #14
0
/* Initialize connection */
CONN *conn_init(int fd, char *ip, int port)
{
    CONN *conn = NULL;

    if(fd > 0 && ip && port > 0 && (conn = calloc(1, sizeof(CONN))))
    {
        conn->fd = fd;
        strcpy(conn->ip, ip);
        conn->port = port;
        TIMER_INIT(conn->timer);
        MB_INIT(conn->buffer, MB_BLOCK_SIZE);
        MB_INIT(conn->packet, MB_BLOCK_SIZE);
        MB_INIT(conn->cache, MB_BLOCK_SIZE);
        MB_INIT(conn->oob, MB_BLOCK_SIZE);
        CK_INIT(conn->chunk);
        conn->send_queue            = QUEUE_INIT();
        conn->event                 = ev_init();
        conn->set                   = conn_set;
        conn->close                 = conn_close;
        conn->over                  = conn_over;
        conn->terminate             = conn_terminate;
        conn->start_cstate          = conn_start_cstate;
        conn->over_cstate           = conn_over_cstate;
        conn->set_timeout           = conn_set_timeout;
        conn->set_session           = conn_set_session;
        conn->push_message          = conn_push_message;
        conn->read_handler          = conn_read_handler;
        conn->write_handler         = conn_write_handler;
        conn->packet_reader         = conn_packet_reader;
        conn->packet_handler        = conn_packet_handler;
        conn->oob_handler           = conn_oob_handler;
        conn->data_handler          = conn_data_handler;
        conn->transaction_handler   = conn_transaction_handler;
        conn->save_cache            = conn_save_cache;
        conn->chunk_reader          = conn_chunk_reader;
        conn->recv_chunk            = conn_recv_chunk;
        conn->push_chunk            = conn_push_chunk;
        conn->recv_file             = conn_recv_file;
        conn->push_file             = conn_push_file;
        conn->set_session           = conn_set_session;
        conn->clean                 = conn_clean;
    }
    return conn;
}
Beispiel #15
0
void
view_glut_render()
{
    struct view* view = g_glut_view;
    if ( view == NULL )
        return;
    
    TIMER_INIT();
    TIMER_START();
    
    view_render(view);
    
    glutSwapBuffers();
    
    TIMER_STOP_PRINT("View: GlutRender");
    
    usleep(1000);
    
    glutPostRedisplay();
}
Beispiel #16
0
//-------------------------------------------------------------------------------------------
// MAIN Routine
//-------------------------------------------------------------------------------------------
void main (void)
{
	bit restart = 0;
	unsigned int randnum = 0;
	
	WDTCN = 0xDE;					// Disable the watchdog timer
	WDTCN = 0xAD;					// Note: = "DEAD"!

	SYSCLK_INIT();					// Initialize the oscillator.
	PORT_INIT();					// Configure the Crossbar and GPIO.
	UART0_INIT();					// Initialize UART0.
	INTERRUPT_INIT();				// Initialize Interrupts
	TIMER_INIT();

	SFRPAGE = LEGACY_PAGE;
	IT0		= 1;					// /INT0 is edge triggered, falling-edge.

	SFRPAGE = UART0_PAGE;			// Direct output to UART0
	
	printf("\033[2J");				// Erase screen and move cursor to the home posiiton.
	printf("MPS Interrupt Switch Test\n\n\r");
	printf("Ground /INT0 on P0.2 to generate an interrupt.\n\n\r");
	SFRPAGE = CONFIG_PAGE;

	EX0		= 1;					// Enable Ext Int 0 only after everything is settled.
	SFRPAGE = UART0_PAGE; 
	while (1)
	{
		if (count > 340) {
			count = 0;
			sec_elapsed++;
			printf("Seconds Elapsed: %d\r\n", sec_elapsed);
		} 
		if(pbFlag){
			// If interrupt flag is set to 1
			printf("PB Pressed!\r\n");
			pbFlag = 0;
		}
	}
}
/* initialization */
static void initialize(void) {
    int i;

    for (i=0; i<NMSGS-1; i++)
        messages[i].next = &messages[i+1];
    messages[NMSGS-1].next = NULL;
    
    for (i=0; i<NTHREADS-1; i++)
        threads[i].next = &threads[i+1];
    threads[NTHREADS-1].next = NULL;
    
    for (i=0; i<NTHREADS; i++) {
        setjmp( threads[i].context );
        SETSTACK( &threads[i].context, &stacks[i] );
        SETPC( &threads[i].context, run );
        threads[i].waitsFor = NULL;
    }

    thread0.next = NULL;
    thread0.waitsFor = NULL;
    thread0.msg = NULL;
    
    TIMER_INIT();
}
Beispiel #18
0
/** Documented at declaration */
int
dxt_encoder_compress(struct dxt_encoder* encoder, DXT_IMAGE_TYPE* image, unsigned char* image_compressed)
{        
#ifdef RTDXT_DEBUG
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[0]);
#endif
#ifdef RTDXT_DEBUG_HOST
    TIMER_INIT();

    TIMER_START();
#endif
#ifdef HAVE_GPUPERFAPI
    GPA_BeginPass();
    GPA_BeginSample(0);
#endif
#ifdef USE_PBO_DXT_ENCODER
    GLubyte *ptr;
#endif

    int data_size = encoder->width * encoder->height;
    switch(encoder->format) {
            case DXT_FORMAT_YUV422:
                data_size *= 2;
                break;
            case DXT_FORMAT_RGB:
                data_size *= 3;
                break;
            case DXT_FORMAT_RGBA:
            case DXT_FORMAT_YUV:
                data_size *= 4;
                break;
    }

    switch(encoder->format) {
            case DXT_FORMAT_YUV422:
                        glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo444_id);
                        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, encoder->texture_id, 0);
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_yuv422);
                        
                        glPushAttrib(GL_VIEWPORT_BIT);
                        glViewport( 0, 0, encoder->width, encoder->height);
                
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height,  GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width / 2, encoder->height,  GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image);
#endif
                        glUseProgram(encoder->yuv422_to_444_program);
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[1]);
#endif
#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_BeginSample(1);
#endif
                        
                        if(encoder->legacy) {
                            glBegin(GL_QUADS);
                            glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
                            glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
                            glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
                            glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
                            glEnd();
                        } else {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
                            // Compress
                            glBindVertexArray(encoder->g_vao_422);
                            //glDrawElements(GL_TRIANGLE_STRIP, sizeof(m_quad.indices) / sizeof(m_quad.indices[0]), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));
                            glDrawArrays(GL_TRIANGLES, 0, 6);
                            glBindVertexArray(0);
#endif
                        }
                        
                        glPopAttrib();
                        /* there is some problem with restoring viewport state (Mac OS Lion, OpenGL 3.2) */
                        glViewport( 0, 0, (encoder->width + 3) / 4, encoder->height / 4);
                        
                        //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
                        
                        glUseProgram(encoder->program_compress);
                        glBindFramebuffer(GL_FRAMEBUFFER, encoder->fbo_id);
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
                
                        //gl_check_error();
                        break;
                case DXT_FORMAT_YUV:
                case DXT_FORMAT_RGBA:
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
#endif

                        break;
                case DXT_FORMAT_RGB:
                        glBindTexture(GL_TEXTURE_2D, encoder->texture_id);
#ifdef USE_PBO_DXT_ENCODER
                        glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, encoder->pbo_in); // current pbo
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
                        glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, data_size, 0, GL_STREAM_DRAW_ARB);
                        ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
                        if(ptr)
                        {
                            // update data directly on the mapped buffer
                            memcpy(ptr, image, data_size); 
                            glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
                        }
#else
                        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, encoder->width, encoder->height, GL_RGB, GL_UNSIGNED_BYTE, image);
#endif
                        break;
    }
#ifdef RTDXT_DEBUG
    glEndQuery(GL_TIME_ELAPSED_EXT);
    glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[2]);
#endif
#ifdef RTDXT_DEBUG_HOST
    glFinish();
    TIMER_STOP_PRINT("Tex Load (+->444): ");
    TIMER_START();
#endif

#ifdef HAVE_GPUPERFAPI
    GPA_EndSample();
    GPA_BeginSample(2);
#endif

    return dxt_encoder_compress_texture(encoder, encoder->texture_id, image_compressed);
}
Beispiel #19
0
int main( int argc, char* argv[] ) {
	gnd::opsm::cmap_t				cmap;					// counting map
	gnd::opsm::map_t					map;					// scan matching map
	gnd::vector::fixed_column<3>	pos;					// matching result
	FILE							*fp;					// matched scan data (input)

	gnd::conf::parameter_array<char, 256> cmap_dir = {
			"cmap-dir", 							// item name
			"./", 									// default value
			"cmap directory path" 					// comment
	};
	gnd::conf::parameter_array<double, 3> pos_ini = {
			"init-pos", 							// item name
			{0, 0, 0}, 								// default value
			"initial position for scan matching (x[m], y[m], theta[deg])" 	// comment
	};
	gnd::conf::parameter_array<char, 256> scan_file = {
			"scan-data",							// item name
			"scan.txt",						// default value
			"scan data file path"					// comment
	};

	{ // ---> debug mode
		gnd::opsm::debug_set_log_level(2);
		gnd::gridmap::debug_set_log_level(2);
	} // <--- debug mode

	{ // ---> initialize
		int ret;
		gnd::conf::file_stream fs;

		// set parameter item and default parameter
		if( argc < 2 ) {
			static const char fname[] = "_scan-matching.conf";
			::fprintf(stderr, " error: missing file operand\n");
			::fprintf(stderr, "        please input configuration file path\n");
			::fprintf(stderr, "        e.g.: %s scan-matching.conf\n", argv[0]);
			::fprintf(stderr, "        ... \n");
			// write configuration file
			gnd::conf::set_parameter(&fs, &cmap_dir);
			gnd::conf::set_parameter(&fs, &pos_ini);
			gnd::conf::set_parameter(&fs, &scan_file);
			fs.write(fname);
			::fprintf(stderr, "         => generate configuration file template \"%s\"\n", fname);

			return -1;
		}

		// configuration file read
		ret = fs.read(argv[1]);
		if( ret < 0 ) {
			::fprintf(stderr, " error: fail to read configuration file\n");
			return -1;
		}

		// get parameter value
		gnd::conf::get_parameter(&fs, &cmap_dir);
		gnd::conf::get_parameter(&fs, &pos_ini);
		gnd::conf::get_parameter(&fs, &scan_file);

		if( !cmap_dir.value[0] ) {
			::fprintf(stdout, " error: missing counting map\n");
			::fprintf(stdout, " please set counting map directory\n");
			return -1;
		}

		// read counting map
		ret = gnd::opsm::read_counting_map( &cmap, cmap_dir.value );
		if( ret < 0 ) {
			::fprintf(stderr, " error: fail to read counting map form directory \"%s\"\n", cmap_dir.value);
			return 0;
		}

		// build scan matching map
		ret = gnd::opsm::build_map( &map, &cmap );

		if( !scan_file.value[0] ) {
			::fprintf(stdout, " error: missing scan data\n");
			::fprintf(stdout, "        please set scan data file\n");
			return -1;
		}

		// open scan data file
		fp = ::fopen( scan_file.value, "r" );
		if( !fp ) {
			::fprintf(stdout, " error: fail to open \"%s\"\n", scan_file.value);
			return -1;
		}

	} // <--- initialize



	{ // ---> operation
		int ret;
		gnd::opsm::mcl						mcl;		// quasi monte calro method class
		gnd::opsm::mcl::initial_parameter	mcl_ini;

		gnd::vector::fixed_column<3> 		delta;
		double 								likelihood;
		int 								cnt = 0;

		// timer init (for linux)
		TIMER_INIT();

		// set map
		mcl.set_map(&map);

		// set random seed
		gnd::random_set_seed();

		// initial position
		mcl_ini.pos[0] = pos_ini.value[0];
		mcl_ini.pos[1] = pos_ini.value[1];
		mcl_ini.pos[2] = pos_ini.value[2] * 3.141592 / 180;

		// number of particle
		mcl_ini.n = 300;

		// initial particles distribution
		// co-variance matrix
		gnd::matrix::set_zero( &mcl_ini.var_ini );
		mcl_ini.var_ini[0][0] = 0.1 * 0.1;									// x's standard deviation is 0.1
		mcl_ini.var_ini[1][1] = 0.1 * 0.1;									// y's standard deviation is 0.1
		mcl_ini.var_ini[2][2] = (10 * 3.141592 / 180) * (10 * 3.141592 / 180);	// orientation's standard deviation is 5 [deg]

		// set initial parameter
		mcl.begin( &mcl_ini );


		{// ---> set scan data (robot coordinate) and file out scan data on initial position
			FILE					*fp_ini;				// scan data on initial position (file out)
			double cosv = cos(mcl_ini.pos[2]);
			double sinv = sin(mcl_ini.pos[2]);

			// open output file (scan on initial position)
			fp_ini = ::fopen("scan-on-init-pos.txt", "w");
			if( !fp_ini ) {
				::fprintf(stdout, " error: fail to open \"%s\"\n", "scan-on-init-pos.txt");
				return -1;
			}

			while( !::feof(fp)  ) {
				double x, y;
				// read data file
				ret = ::fscanf(fp, "%lf %lf\n", &x, &y);
				// when read all data, break
				if( ret < 0 ) break;

				// set scan data
				mcl.set_scan_point( x, y );

				// file out scan data on initial position
				::fprintf(fp_ini, "%lf %lf\n",
						x * cosv - y * sinv + mcl_ini.pos[0],
						x * sinv + y * cosv + mcl_ini.pos[1]);
			}

			::fclose(fp_ini);
		} // ---> set scan data (robot coordinate) and file out scan data on initial position


		// set convergence test parameter
		// difference from previous position 0.001m in distance and 0.1deg in orientation
		mcl.set_converge_threshold( 0.001, 0.01 * 3.141592 / 180 );

		// show initial position
		::fprintf(stdout, "       init pos = %lf, %lf, %lf\n", mcl_ini.pos[0],  mcl_ini.pos[1],  mcl_ini.pos[2] * 180 / 3.141592);
		::fprintf(stdout, " scan point num = %d\n",  mcl.nscan_point());

		::fprintf(stdout, "\n");
		::fprintf(stdout, " => Scan Matching Begin\n");
		// iterative optimization
		double t = 0, l = 0;
		do {
			// optimize
			TIMER_BEGIN();
			mcl.iterate( &delta, &pos, &likelihood);
			TIMER_REC(&t, &l);

			cnt++;
			// show result
			::fprintf(stdout, "-------- optimization loop %d --------\n", cnt);
			::fprintf(stdout, "       delta = %lf, %lf, %lf\n", delta[0], delta[1], delta[2] * 180 / 3.141592);
			::fprintf(stdout, "         pos = %lf, %lf, %lf\n", pos[0], pos[1], pos[2] * 180 / 3.141592);
			::fprintf(stdout, "  likelihood = %lf\n", likelihood);
			TIMER_SHOW(&t, &l);
			::fprintf(stdout, "\n");
			::fprintf(stdout, "\n");

			// convergence test
		} while( !mcl.converge_test() || cnt < 5);

		::fprintf(stdout, " ... Finish\n");

	} // <--- operation


	{ // ---> finalize

		{ // ---> output matched scan data (global coordinate)
			int ret;
			double cosv = cos(pos[2]);
			double sinv = sin(pos[2]);
			FILE					*fp_m;					// scan data on matching position (file out)

			::fprintf(stdout, " => file-out matched scan points on global coordinate\n");


			// open output file (scan on matching position)
			fp_m = ::fopen("scan-on-match-pos.txt", "w");
			if( !fp_m ) {
				::fprintf(stdout, " error: fail to open \"%s\"\n", "scan-on-match-pos.txt");
				return -1;
			}

			// ---> fileout
			::fseek(fp, 0, SEEK_SET);
			while( !::feof(fp)  ) {
				double x, y;
				// read data file
				ret = ::fscanf(fp, "%lf %lf\n", &x, &y);
				// when read all data, break
				if( ret < 0 ) break;

				::fprintf(fp_m, "%lf %lf\n",
						x * cosv - y * sinv + pos[0],
						x * sinv + y * cosv + pos[1]
				);

			} // ---> fileout

			::fprintf(stdout, " ... output \"matched-scan-data.txt\"\n");

			// file close
			::fclose(fp_m);
		} // <--- output matched scan data (global coordinate)

		// file close
		::fclose(fp);

		gnd::opsm::destroy_counting_map(&cmap);
		gnd::opsm::destroy_map(&map);
	} // <--- finalize


	return 0;
}
Beispiel #20
0
//gcc -o dmap dmap.c -DDMAP_TEST -DTEST_INS -DHAVE_PTHREAD -lpthread && ./dmap
int main()
{
    DMAP *dmap = NULL;
    int i = 0, j = 0, n = 0, total = 0, no = 0, stat[MASK], stat2[MASK];
    double val = 0, from = 0, to = 0, *res = NULL;
    double inputs[256], nos[256], last[256];
    double all = 0;
    time_t stime = 0, etime = 0;
    void *timer = NULL;

    if((dmap = dmap_init("/tmp/1.idx")))
    {
        res = (double *)calloc(60000000, sizeof(double));
        TIMER_INIT(timer);
#ifdef TEST_INS
        //fprintf(stdout, "sizeof(stat):%d\n", sizeof(stat));
        memset(stat, 0, sizeof(stat));
        memset(stat2, 0, sizeof(stat2));
        srand(time(NULL));
        n = 256;
        for(i = 0; i < n; i++)
        {
            no = (rand()%MASK);
            nos[i] = no;
            if((i % 3) == 0)
                inputs[i] = no * -1;
            else
                inputs[i] = no;
        }
        TIMER_RESET(timer);
        for(i = 1; i < 20000000; i++)
        {
           j = (rand()%n);
           val = inputs[j];
           no = nos[j];
           stat[no]++;
           dmap_set(dmap, i, val);
           last[j] = i;
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "set() 40000000 data, time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        for(i = 0; i < n; i++)
        {
            dmap_del(dmap, last[i]);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "del() time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        for(i = 0; i < n; i++)
        {
            val = inputs[i];
            no = nos[i];
            stat2[no] = dmap_in(dmap, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "in() time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        total = dmap_ins(dmap, inputs, n, NULL);
        TIMER_SAMPLE(timer);
        fprintf(stdout, "ins(keys, NULL) total:%d time used:%lld\n", total, PT_LU_USEC(timer));
        TIMER_RESET(timer);
        total = dmap_ins(dmap, inputs, n, res);
        TIMER_SAMPLE(timer);
        fprintf(stdout, "ins(keys, res:%p) total:%d time used:%lld\n", res, total, PT_LU_USEC(timer));
        for(i = 0; i < n; i++)
        {
            j = nos[i];
            if(stat[j] != stat2[j])
                fprintf(stdout, "%d:%d/%d::%d\n", j, stat[j], stat2[j], inputs[i]);
        }
#ifdef OUT_ALL
        for(i = 0; i < total; i++)
        {
            fprintf(stdout, "%d:%d\n", i, res[i]);
        }
#endif
#endif
        /*
        for(i = 0; i < dmap->state->count; i++)
        {
            fprintf(stdout, "%d:{min:%d max:%d}(%d)\n", i, dmap->slots[i].min, dmap->slots[i].max, dmap->slots[i].count);
        }
        */
#ifdef TEST_RANGEFILTER
            dmap_set(dmap, 1, 1234567);
            dmap_set(dmap, 2, 1567890);
            fprintf(stdout, "rangefrom():%d\n", dmap_rangefrom(dmap, 1569000, NULL));
            fprintf(stdout, "rangeto():%d\n", dmap_rangeto(dmap, 1111111, NULL));
            fprintf(stdout, "range():%d\n", dmap_range(dmap, 1111111, 1600000, NULL));
#endif
#ifdef TEST_RANGE
        srand(time(NULL));
        TIMER_RESET(timer);
        for(i = 1; i < 40000000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            dmap_set(dmap, i, val);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "set() 40000000 timestamps,  time used:%lld\n", PT_LU_USEC(timer));
        fflush(stdout);
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            all += dmap_rangefrom(dmap, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "rangefrom() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));
        fflush(stdout);
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            all += dmap_rangeto(dmap, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "rangeto() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));
        fflush(stdout);
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            from = 1356969600 + (rand()%31536000);
            to = from + rand()%31536000;
            all += dmap_range(dmap, from, to, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "range(%p) 1000 times total:%lld, time used:%lld\n", res, (long long int)all, PT_LU_USEC(timer));
        fflush(stdout);
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            from = 1356969600 + (rand()%31536000);
            to = from + rand()%31536000;
            all += dmap_range(dmap, from, to, NULL);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "range(null) 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));
        fflush(stdout);

#endif
        dmap_close(dmap);
        TIMER_CLEAN(timer);
        free(res);
    }
}
Beispiel #21
0
int main(int argc, char **argv)
{
    pid_t pid;
    char *url = NULL, *urllist = NULL, line[HTTP_BUF_SIZE], *s = NULL, *p = NULL, ch = 0;
    struct hostent *hent = NULL;
    int n = 0, log_level = 0, tcp_option = 0, socket_option = 0, niodaemons = 0, is_realtime = 0;

    /* get configure file */
    while((ch = getopt(argc, argv, "vqpkdr:i:s:x:w:l:c:t:n:e:")) != -1)
    {
        switch(ch)
        {
            case 'c': 
                concurrency = atoi(optarg);
                break;
            case 'n':
                ntasks = atoi(optarg);
                break;
            case 'l':
                urllist = optarg;
                break;
            case 'k':
                is_keepalive = 1;
                break;
            case 'w':
                if((n = atoi(optarg)) > 0) workers = n;
                break;
            case 'd':
                is_daemon = 1;
                break;
            case 'q':
                is_quiet = 1;
                break;
            case 'r':
                is_realtime = atoi(optarg);
                break;
            case 't':
                req_timeout = atoi(optarg);
                break;
            case 'p':
                is_post = 1;
                break;
            case 'x':
                tcp_option = atoi(optarg);
                break;
            case 's':
                socket_option = atoi(optarg);
                break;
            case 'i':
                niodaemons = atoi(optarg);
                break;
            case 'e':
                log_level = atoi(optarg);
                break;
            case 'v':
                is_verbosity = 1;
                break;
            case '?':
                url = argv[optind];
                break;
            default:
                break;
        }
    }
    if(url == NULL && optind < argc)
    {
        //fprintf(stdout, "opt:%c optind:%d arg:%s\n", ch, optind, argv[optind]);
        url = argv[optind];
    }
    //fprintf(stdout, "concurrency:%d nrequests:%d is_keepalive:%d is_daemon:%d\n",
    //       concurrency, ntasks, is_keepalive, is_daemon);
    if(url == NULL)
    {
        fprintf(stderr, "Usage:%s [options] http(s)://host:port/path\n"
                "Options:\n\t-c concurrency\n\t-n requests\n"
                "\t-w worker threads\n\t-e log level\n\t-x tcp_option 1:tcp_nodelay\n"
                "\t-s socket_option 1:socket_linger\n\t-i iodaemons\n"
                "\t-t timeout (microseconds, default 1000000)\n"
                "\t-r is_realtime_thread 1:SCHED_FIFO 2:SCHED_RR\n"
                "\t-p is_POST\n\t-v is_verbosity\n\t-l urllist file\n"
                "\t-k is_keepalive\n\t-d is_daemon\n ", argv[0]);
        _exit(-1);
    }
    p = url;
    s = line;
    while(*p != '\0')
    {
        if(*p >= 'A' && *p <= 'Z')
        {
            *s++ = *p++ + 'a' - 'A';
        }
        else if(*((unsigned char *)p) > 127 || *p == 0x20)
        {
            s += sprintf(s, "%%%02x", *((unsigned char *)p));
            ++p;
        }
        else *s++ = *p++;
    }
    *s = '\0';
    s = line;
    if(strncmp(s, "http://", 7) == 0)
    {
        s += 7;
        server_host = s;
    }
    else if(strncmp(s, "https://", 8) == 0)
    {
        s += 8;
        server_host = s;
        server_is_ssl = 1;
    }
    else goto invalid_url;
    while(*s != '\0' && *s != ':' && *s != '/')s++;
    if(*s == ':')
    {
        *s = '\0';
        ++s;
        server_port = atoi(s);          
        while(*s != '\0' && *s != '/')++s;
    }
    if(*s == '/')
    {
        *s = '\0';
        ++s;
        server_url = s;
    }
    while(*s != '\0' && *s != '?')++s;
    if(*s == '?')
    {
        *s = '\0';
        ++s;
        server_argv = s;
    }
invalid_url:
    if(server_host == NULL || server_port <= 0)
    {
        fprintf(stderr, "Invalid url:%s, url must be http://host:port/path?argv "
                " or https://host:port/path?argv\n", url);
        _exit(-1);
    }
    if(urllist) fp = fopen(urllist, "rd");
    if(is_post)
    {
        p = request;
        p += sprintf(p, "POST /%s HTTP/1.1\r\n", server_url);
        p += sprintf(p, "Host: %s:%d\r\n", server_host, server_port);
        if(is_keepalive) p += sprintf(p, "Connection: Keep-Alive\r\n");
        p += sprintf(p, "Content-Length: %d\r\n\r\n", (int)strlen(server_argv));
        p += sprintf(p, "\r\n");
        if(strlen(server_argv)) p += sprintf(p, "%s", server_argv);
        request_len = p - request;
    }
    else
    {
        p = request;
        if(strlen(server_argv) > 0)
            p += sprintf(p, "GET /%s?%s HTTP/1.1\r\n", server_url, server_argv);
        else 
            p += sprintf(p, "GET /%s HTTP/1.1\r\n", server_url);
        p += sprintf(p, "Host: %s:%d\r\n", server_host, server_port);
        if(is_keepalive) p += sprintf(p, "Connection: Keep-Alive\r\n");
        p += sprintf(p, "\r\n");
        request_len = p - request;
    }
    if((hent = gethostbyname(server_host)) == NULL)
    {
        fprintf(stderr, "resolve hostname:%s failed, %s\n", server_host, strerror(h_errno));
        _exit(-1);
    }
    else
    {
        //memcpy(&ip, &(hent->h_addr), sizeof(int));
        sprintf(server_ip, "%s", inet_ntoa(*((struct in_addr *)(hent->h_addr))));
        if(is_verbosity)
        {
            fprintf(stdout, "ip:%s request:%s\n", server_ip, request);
        }
    }
    //_exit(-1);
    /* locale */
    setlocale(LC_ALL, "C");
    /* signal */
    signal(SIGTERM, &benchmark_stop);
    signal(SIGINT,  &benchmark_stop);
    signal(SIGHUP,  &benchmark_stop);
    signal(SIGPIPE, SIG_IGN);
    signal(SIGCHLD, SIG_IGN);
    //daemon
    if(is_daemon)
    {
        pid = fork();
        switch (pid) {
            case -1:
                perror("fork()");
                exit(EXIT_FAILURE);
                break;
            case 0: //child
                if(setsid() == -1)
                    exit(EXIT_FAILURE);
                break;
            default://parent
                _exit(EXIT_SUCCESS);
                break;
        }
    }
    setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, 65536);
    if((sbase = sbase_init()) == NULL)
    {
        exit(EXIT_FAILURE);
        return -1;
    }
    sbase->nchilds = 0;
    sbase->usec_sleep = 1000;
    sbase->connections_limit = 65536;
    TIMER_INIT(timer);
    MUTEX_INIT(mutex);
    if(log_level > 1)sbase->set_evlog(sbase, "/tmp/benchmark_ev.log");
    if(log_level > 0) sbase->set_evlog_level(sbase, log_level);
    if((service = service_init()))
    {
        service->working_mode = 1;
        service->nprocthreads = workers;
        service->niodaemons = niodaemons;
        service->ndaemons = 0;
        service->use_cond_wait = 1;
        service->flag |= SB_USE_OUTDAEMON|SB_USE_COND;
        if(is_realtime) service->flag |= (SB_SCHED_FIFO|SB_SCHED_RR) & is_realtime;
        if(socket_option == 1) service->flag |= SB_SO_LINGER;
        if(tcp_option == 1) service->flag |= SB_TCP_NODELAY;
        service->service_type = C_SERVICE;
        service->family = AF_INET;
        service->sock_type = SOCK_STREAM;
        service->service_name = "benchmark";
        service->session.flags = SB_NONBLOCK;
        service->session.packet_type = PACKET_DELIMITER;
        service->session.packet_delimiter = "\r\n\r\n";
        service->session.packet_delimiter_length = 4;
        service->session.packet_handler = &benchmark_packet_handler;
        service->session.data_handler = &benchmark_data_handler;
        service->session.transaction_handler = &benchmark_trans_handler;
        service->session.error_handler = &benchmark_error_handler;
        service->session.timeout_handler = &benchmark_timeout_handler;
        service->session.ok_handler = &benchmark_ok_handler;
        service->session.buffer_size = 65536;
        service->set_heartbeat(service, 1000000, &benchmark_heartbeat_handler, NULL);
        //service->set_session(service, &session);
        service->set_log(service, "/tmp/benchmark.log");
        service->set_log_level(service, log_level);
        LOGGER_INIT(logger, "/tmp/benchmark_res.log");
        if(sbase->add_service(sbase, service) == 0)
        {
            sbase->running(sbase, 0);
            //sbase->running(sbase, 3600);
            //sbase->running(sbase, 90000000);sbase->stop(sbase);
        }
        else fprintf(stderr, "add service failed, %s", strerror(errno));
    }
    sbase->clean(sbase);
    MUTEX_DESTROY(mutex);
    return 0;
}
Beispiel #22
0
GdkImage *gdkimage_from_pikeimage(struct object *img, int fast, GdkImage *i) {
  GdkColormap *col=gdk_colormap_get_system();
  GdkVisual *vis=gdk_visual_get_system();
  struct image *img_data;
  INT_TYPE x,y;

  TIMER_INIT("Getting extents");

  img_data=(struct image*)get_storage(img, image_program);

  /* 1a: create the actual image... */
  x = img_data->xsize;
  y = img_data->ysize;


  if (x==0 || y==0)
    Pike_error("Size of image must be > 0x0\n");
  if (i) {
    if ((i->width!=x) || (i->height!=y)) {
      gdk_image_destroy((void *)i);
      i=NULL;
    }
  }
  if (!i) {
    PFTIME("Create");
    i=(void *)gdk_image_new(fast,vis,x,y);
  }

  if (!i)
    Pike_error("Failed to create gdkimage\n");

  /* 1b: do the work.. */

  if (vis->type==GDK_VISUAL_TRUE_COLOR || vis->type==GDK_VISUAL_STATIC_GRAY)
    /* no colormap.. */
  {
    int pad=0;
    int native_byteorder;
    PFTIME("Convert");
    if (vis->type==GDK_VISUAL_STATIC_GRAY)
      pgtk2_encode_grey(img_data,i->mem,i->bpp,i->bpl);
    else {
      if (i->bpl!=(i->bpp*x))
	switch(i->bpl & 3) {
	 case  0: pad = 4; break;
	 case  1: pad = 1; break;
	 case  2: pad = 2; break;
	 case  3: pad = 1; break;
	}
      else
	pad=0;
      pgtk2_encode_truecolor_masks(img_data,i->bpp*8,pad*8,
				   (i->byte_order!=1),vis->red_mask,
				   vis->green_mask,vis->blue_mask,
				   i->mem, i->bpl*y);
    }
  } else {
    static int colors_allocated=0;
    static struct object *pike_cmap;
    /* I hate this... colormaps, here we come.. */
    /* This is rather complicated, but:
       1/ build an array of the colors in the colormap
       2/ use that array to build a pike X-image colormap.
       3/ call Image.X.encode_pseudocolor( img, bpp, lpad, depth, colormp )
       4/ copy the actual data to the image..
    */
    if (!colors_allocated) {
#define COLORMAP_SIZE 256
      char allocated[COLORMAP_SIZE];
      int j,i,r,g,b;
      PFTIME("Creating colormap");
      colors_allocated=1;
      MEMSET(allocated,0,sizeof(allocated));
      for (r=0; r<3; r++) for (g=0; g<4; g++) for (b=0; b<3; b++) {
	GdkColor color;
	color.red = (guint16)(r * (65535/2.0));
	color.green = (guint16)(g * (65535/3.0));
	color.blue = (guint16)(b * (65535/2.0));
	color.pixel = 0;
	if (gdk_color_alloc(col,&color))
          if (color.pixel<COLORMAP_SIZE)
            allocated[color.pixel]=1;
      }
      for (r=0; r<6; r++) for (g=0; g<7; g++) for (b=0; b<6; b++) {
	GdkColor color;
	color.red=(guint16)(r*(65535/5.0));
	color.green=(guint16)(g*(65535/6.0));
	color.blue=(guint16)(b*(65535/5.0));
	color.pixel=0;
	if (gdk_color_alloc(col,&color))
          if (color.pixel<COLORMAP_SIZE)
            allocated[color.pixel]=1;
      }

      for (i=0; i<COLORMAP_SIZE; i++) {
	if (allocated[i]) {
	  push_int(col->colors[i].red>>8);
	  push_int(col->colors[i].green>>8);
	  push_int(col->colors[i].blue>>8);
	  f_aggregate(3);
	} else
	  push_int(0);
      }
      f_aggregate(256);
      /* now on stack: the array with colors. */
      pgtk2_get_image_module();
      pgtk2_index_stack("colortable");
      /* on stack: array function */
      Pike_sp[0]=Pike_sp[-1];
      Pike_sp[-1]=Pike_sp[-2];
      Pike_sp[-2]=Pike_sp[0];
      /* on stack: function array */
      PFTIME("Creating colormap obj");
      apply_svalue(Pike_sp-2,1);
      /* on stack: function cmap */
      get_all_args("internal",1,"%o",&pike_cmap);
      pike_cmap->refs+=100; /* lets keep this one.. :-) */
      push_int(8);
      push_int(8);
      push_int(8);
      apply(pike_cmap,"rigid",3);
      pop_stack();
      apply(pike_cmap,"ordered",0);
      pop_stack();
      pop_stack();
    }
Beispiel #23
0
/** Documented at declaration */
int
dxt_decoder_decompress(struct dxt_decoder* decoder, unsigned char* image_compressed, DXT_IMAGE_TYPE* image)
{    
#ifdef RTDXT_DEBUG
    TIMER_INIT();
    
    TIMER_START();
#endif
    glBindTexture(GL_TEXTURE_2D, decoder->compressed_tex);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    if ( decoder->type == DXT_TYPE_DXT5_YCOCG )
        glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
                        (decoder->width + 3) / 4 * 4, decoder->height, 0, ((decoder->width + 3) / 4 * 4) * ((decoder->height + 3) / 4 * 4), image_compressed);
    else
        glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
                        (decoder->width + 3) / 4 * 4, decoder->height, 0, ((decoder->width + 3) / 4 * 4) * ((decoder->height + 3) / 4 * 4) / 2, image_compressed);
#ifdef RTDXT_DEBUG
    glFinish();
    TIMER_STOP_PRINT("Texture Load:      ");
    
    TIMER_START();
#endif
    
    // Render to framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, decoder->fbo_rgba);
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0, 0, decoder->width, decoder->height);

    glUseProgram(decoder->program_display);
    
    glBindTexture(GL_TEXTURE_2D, decoder->compressed_tex);
    
    if(decoder->legacy) {
        glBegin(GL_QUADS);
        glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
        glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
        glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
        glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
        glEnd();
    } else {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
        glBindVertexArray(decoder->g_vao);
        glDrawArrays(GL_TRIANGLES, 0, 6);
        glBindVertexArray(0);
#endif
    }
    
    glUseProgram(0);
#ifdef RTDXT_DEBUG
    glFinish();
    TIMER_STOP_PRINT("Texture Decompress:");
    
    TIMER_START();
#endif
    if(decoder->out_format != DXT_FORMAT_YUV422) { /* so RGBA */
            // Disable framebuffer
            glReadPixels(0, 0, decoder->width, decoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
    } else {

            glBindFramebuffer(GL_FRAMEBUFFER, decoder->fbo_yuv422);
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, decoder->uncompressed_yuv422_tex, 0);
            
            glBindTexture(GL_TEXTURE_2D, decoder->uncompressed_rgba_tex); /* to texturing unit 0 */

            glPushAttrib(GL_VIEWPORT_BIT);
            glViewport( 0, 0, decoder->width / 2, decoder->height);

            glUseProgram(decoder->program_rgba_to_yuv422);
            
            if(decoder->legacy) {
                glBegin(GL_QUADS);
                glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
                glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
                glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
                glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
                glEnd();
            } else {
#if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11
                glBindVertexArray(decoder->g_vao_422);
                glDrawArrays(GL_TRIANGLES, 0, 6);
                glBindVertexArray(0);
#endif
            }
            
            glPopAttrib();

            glReadPixels(0, 0, decoder->width / 2, decoder->height, GL_RGBA, DXT_IMAGE_GL_TYPE, image);
            glBindFramebuffer(GL_FRAMEBUFFER, 0);
            glUseProgram(0);
    }
    
#ifdef RTDXT_DEBUG    
    glFinish();
    TIMER_STOP_PRINT("Texture Save:      ");
#endif
    
    return 0;
}
Beispiel #24
0
//rm -rf /tmp/1.idx* && gcc -O2 -o lkv lkv.c -DLKV_TEST -DTEST_KV -DHAVE_PTHREAD -lpthread && ./lkv
int main()
{
    LKV *lkv = NULL;
    int i = 0, j = 0, n = 0, total = 0, no = 0, stat[MASK], stat2[MASK],
        v = 0, num = 1000000, base = 60000000;
    int64_t val = 0, from = 0, to = 0, *res = NULL, all_mask = 200000;
    int64_t inputs[256], nos[256], last[256], tall[200000];
    int64_t all = 0;
    time_t stime = 0, etime = 0;
    void *timer = NULL;

    if((lkv = lkv_init("/tmp/1.idx")))
    {
        res = (int64_t *)calloc(base, sizeof(int64_t));
        TIMER_INIT(timer);
#ifdef TEST_KV
        TIMER_RESET(timer);
        for(i = 0; i < num; i++)
        {
            no = random()%base;
            LKV_SET(lkv, no, i);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "set(%d) time used:%lld\n", num, PT_LU_USEC(timer));
        TIMER_RESET(timer);
        for(i = 0; i < num; i++)
        {
            no = random()%base;
            v = LKV_GET(lkv, no);
        }
        fprintf(stdout, "get(%d) time used:%lld\n", num, PT_LU_USEC(timer));
#endif

#ifdef TEST_RFROM
            lkv_set(lkv, 1, 22);
            lkv_set(lkv, 2, 25);
            lkv_set(lkv, 3, 20);
            lkv_set(lkv, 4, 13);
            lkv_set(lkv, 6, 22);
            n = lkv_rangefrom(lkv, 21, NULL);
            fprintf(stdout, "rangefrom(21) => %d\n", n);
#endif
#ifdef TEST_DEB
        /*
            n = lkv_in(lkv, 16615, NULL);
            fprintf(stdout, "16615:%d\n", n);
        */
        n = 0;
        for(i = 0; i < lkv->state->count; i++)
        {
            /*
            if(lkv->slots[i].min <= 26650 && lkv->slots[i].max >= 26650)
            {
                fprintf(stdout, "%d:[min:%d max:%d]\n", i, lkv->slots[i].min, lkv->slots[i].max);
            }
            */
            n+= lkv->slots[i].count;
        }
        fprintf(stdout, "total:%d\n", n);
#endif
#ifdef TEST_IN
        for(i = 0; i < all_mask; i++)
        {
            tall[i] = 0;
        }
        for(i = 80000000; i > 0; i--)
        {
            no = (rand()%all_mask);
            lkv_set(lkv, i, no);
            tall[no]++;
        }
        for(i = 0; i < all_mask; i++)
        {
            n = lkv_in(lkv, i, NULL);
            if(n != tall[i])
                fprintf(stdout, "%d:[%d/%d]\n", i, n, tall[i]);
        }
#endif
#ifdef TEST_ALL
        for(i = 0; i < all_mask; i++)
        {
            tall[i] = 0;
        }
        for(i = 80000000; i > 0; i--)
        {
            no = (rand()%all_mask);
            lkv_set(lkv, i, no);
            tall[no]++;
        }
        no = (rand()%all_mask);
        total = 0;for(i = no; i < all_mask; i++) total += tall[i];
        fprintf(stdout, "rangefrom(%d):%d/%d\n", no, lkv_rangefrom(lkv, no, NULL), total);
        total = 0;for(i = 0; i <= no; i++) total += tall[i];
        fprintf(stdout, "rangeto(%d):%d/%d\n", no, lkv_rangeto(lkv, no, NULL), total);
        from = (rand()%all_mask);
        to = (rand()%all_mask);
        if(from > to){from += to; to = from - to; from = from - to;}
        total = 0;for(i = from; i <= to; i++) total += tall[i];
        fprintf(stdout, "range(%d,%d):%d/%d\n", from, no, lkv_range(lkv, from, to, NULL), total);
        for(i = 0; i < all_mask; i++)
        {
            n = lkv_in(lkv, i, NULL);
            if(n != tall[i])
                fprintf(stdout, "%d:[%d/%d]\n", i, n, tall[i]);
        }
#endif
#ifdef TEST_INS
        //fprintf(stdout, "sizeof(stat):%d\n", sizeof(stat));
        memset(stat, 0, sizeof(stat));
        memset(stat2, 0, sizeof(stat2));
        srand(time(NULL));
        n = 256;
        for(i = 0; i < n; i++)
        {
            no = (rand()%MASK);
            nos[i] = no;
            if((i % 3) == 0)
                inputs[i] = no * -1;
            else
                inputs[i] = no;
        }
        TIMER_RESET(timer);
        for(i = 1; i < 20000000; i++)
        {
           j = (rand()%n);
           val = inputs[j];
           no = nos[j];
           stat[no]++;
           lkv_set(lkv, i, val);
           last[j] = i;
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "set() 40000000 data, time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        for(i = 0; i < n; i++)
        {
            lkv_del(lkv, last[i]);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "del() time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        for(i = 0; i < n; i++)
        {
            val = inputs[i];
            no = nos[i];
            stat2[no] = lkv_in(lkv, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "in() time used:%lld\n", PT_LU_USEC(timer));
        TIMER_RESET(timer);
        total = lkv_ins(lkv, inputs, n, NULL);
        TIMER_SAMPLE(timer);
        fprintf(stdout, "ins(keys, NULL) total:%d time used:%lld\n", total, PT_LU_USEC(timer));
        TIMER_RESET(timer);
        total = lkv_ins(lkv, inputs, n, res);
        TIMER_SAMPLE(timer);
        fprintf(stdout, "ins(keys, res:%p) total:%d time used:%lld\n", res, total, PT_LU_USEC(timer));
        for(i = 0; i < n; i++)
        {
            j = nos[i];
            if(stat[j] != stat2[j])
                fprintf(stdout, "%d:%d/%d::%d\n", j, stat[j], stat2[j], inputs[i]);
        }
#ifdef OUT_ALL
        for(i = 0; i < total; i++)
        {
            fprintf(stdout, "%d:%d\n", i, res[i]);
        }
#endif
#endif
        /*
        for(i = 0; i < lkv->state->count; i++)
        {
            fprintf(stdout, "%d:{min:%d max:%d}(%d)\n", i, lkv->slots[i].min, lkv->slots[i].max, lkv->slots[i].count);
        }
        */
#ifdef TEST_RANGEFILTER
            lkv_set(lkv, 1, 1234567);
            lkv_set(lkv, 2, 1567890);
            fprintf(stdout, "rangefrom():%d\n", lkv_rangefrom(lkv, 1569000, NULL));
            fprintf(stdout, "rangeto():%d\n", lkv_rangeto(lkv, 1111111, NULL));
            fprintf(stdout, "range():%d\n", lkv_range(lkv, 1111111, 1400000, NULL));
#endif
#ifdef TEST_RANGE
        srand(time(NULL));
        TIMER_RESET(timer);
        for(i = 1; i < 40000000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            lkv_set(lkv, i, val);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "set() 40000000 timestamps,  time used:%lld\n", PT_LU_USEC(timer));
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            all += lkv_rangefrom(lkv, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "rangefrom() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            val = 1356969600 + (rand()%31536000);
            all += lkv_rangeto(lkv, val, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "rangeto() 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            from = 1356969600 + (rand()%31536000);
            to = from + rand()%31536000;
            all += lkv_range(lkv, from, to, res);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "range(%p) 1000 times total:%lld, time used:%lld\n", res, (long long int)all, PT_LU_USEC(timer));
        srand(time(NULL));
        TIMER_RESET(timer);
        all = 0;
        for(i = 0; i < 1000; i++)
        {
            from = 1356969600 + (rand()%31536000);
            to = from + rand()%31536000;
            all += lkv_range(lkv, from, to, NULL);
        }
        TIMER_SAMPLE(timer);
        fprintf(stdout, "range(null) 1000 times total:%lld, time used:%lld\n", (long long int)all, PT_LU_USEC(timer));

#endif
        lkv_close(lkv);
        TIMER_CLEAN(timer);
        free(res);
    }
}
Beispiel #25
0
int main(int argc, char **argv)
{
    int i = 0, k = 0, x = 0, mid = 0, qid = 0, port = 0, flag = 0, dbport = 0, 
        isdaemon = 0, isout = 0, packetid = 0, ret = -1, from = 0, to = 0;
    char tmp[XX_BUF_SIZE], url[XX_URL_MAX],*ip = NULL, *dbhost = NULL, 
         block[XX_PACKET_MAX * sizeof(int64_t)], ch = 0;
    int64_t *list = NULL, key = 0, rand = 0;
    unsigned char digest[MD5_LEN];
    BJSON request = {0};
    void *timer = NULL;
    BREC record = {0};
    MTASK mtask = {0};
    pid_t pid = 0;
    DBASE db = {0};

    /* get configure file */
    while((ch = getopt(argc, argv, "h:p:m:q:i:x:n:c:f:t:od")) != -1)
    {
        switch(ch)
        {
            case 'h':
                ip = optarg;
                break;
            case 'p':
                port = atoi(optarg);
                break;
            case 'm':
                mid = atoi(optarg);
                break;
            case 'q':
                qid = atoi(optarg);
                break;
            case 'i':
                dbhost = optarg;
                break;
            case 'x':
                dbport = atoi(optarg);
                break;
            case 'f':
                from = atoi(optarg);
                break;
            case 't':
                to = atoi(optarg);
                break;
            case 'o':
                isout = 1;
                break;
            case 'd':
                isdaemon = 1;
                break;
            default:
                break;
            }
    }
    if(ip == NULL || port <= 0 || (qid == 0 && mid == 0) || dbhost == NULL || dbport <= 0)
    {
        fprintf(stderr, "Usage:%s -h qtask_host -p qtask_port -m commitid -q queueid "
                "-i dbhost -x dbport -f from -t to -o output -d is_working_daemon\n", argv[0]);
        _exit(-1);
    }
    /* daemon */
    if(isdaemon)
    {
        pid = fork();
        switch (pid) {
            case -1:
                perror("fork()");
                exit(EXIT_FAILURE);
                break;
            case 0: /* child process */
                if(setsid() == -1)
                    exit(EXIT_FAILURE);
                break;
            default:/* parent */
                _exit(EXIT_SUCCESS);
                break;
        }
    }
    if(mtask_set(&mtask, ip, port, mid, qid) == 0 
            && mtask_connect(&mtask) == 0)
    {
        if(dbase_set(&db, dbhost, dbport) != 0 || dbase_connect(&db) != 0)
        {
            fprintf(stderr, "connect to db[%s:%d] failed, %s\n", dbhost, dbport, strerror(errno));
            _exit(-1);
        }
        list = (int64_t *)block;
        //sprintf(ns, "%s.%s", dbname, collection);
        TIMER_INIT(timer);
        BJSON_INIT(request);
        k = from;
        if(to <= 0) to = from + 10000000;
        do
        {
            TIMER_SAMPLE(timer);
            rand = random();
            flag = 0;
            //if((rand%33) == 0) flag = MTASK_TO_QHEAD;
            x = 0;
            while(x < XX_PACKET_MAX)
            {
                //fprintf(stdout, "%s::%d ns:%s OK\n", __FILE__, __LINE__, ns);
                sprintf(url, "http://demo.com/%d.html", ++k);
                memset(digest, 0, MD5_LEN);
                md5((unsigned char *)url, strlen(url), digest);
                key = *((int64_t *)digest);
                sprintf(tmp, "title %d content %d comment %d", k, k, k);
                brequest_reset(&request);
                bjson_start(&request);
                bjson_append_long(&request, "id", key);
                bjson_new_object(&request, "property");
                bjson_append_int(&request, "status", 1);
                bjson_append_int(&request, "crc", crc32(tmp, strlen(tmp)));
                bjson_append_int(&request, "slevel", 1);
                bjson_append_long(&request, "category", (int64_t)1 << (rand%64));
                bjson_append_double(&request, "rank", 1.0);
                bjson_finish_object(&request);
                //fprintf(stdout, "%s::%d key:%lld\n", __FILE__, __LINE__, key);
                bjson_new_object(&request, "text_index");
                sprintf(tmp, "title %d", k);
                bjson_append_string(&request, "title", tmp);
                sprintf(tmp, "content %d", k);
                bjson_append_string(&request, "content", tmp);
                sprintf(tmp, "comment %d", k);
                bjson_append_string(&request, "comment", tmp);
                bjson_finish_object(&request);
                //fprintf(stdout, "%s::%d key:%lld\n", __FILE__, __LINE__, key);
                bjson_new_object(&request, "int_index");
                bjson_append_int(&request, "0", rand/3);
                bjson_append_int(&request, "1", rand/9);
                bjson_append_int(&request, "2", rand/31);
                bjson_finish_object(&request);
                bjson_new_object(&request, "long_index");
                bjson_append_long(&request, "0", rand/2);
                bjson_append_long(&request, "1", rand/7);
                bjson_append_long(&request, "2", rand/21);
                bjson_finish_object(&request);
                bjson_new_object(&request, "double_index");
                bjson_append_double(&request, "0", (double)rand/(double)33);
                bjson_append_double(&request, "1", (double)rand/(double)53);
                bjson_append_double(&request, "2", (double)rand/(double)73);
                bjson_finish_object(&request);
                bjson_new_object(&request, "display");
                bjson_append_string(&request, "url", url);
                sprintf(tmp, "http://demo.com/%d.jpg", k);
                bjson_append_string(&request, "img", tmp);
                bjson_finish_object(&request);
                bjson_finish(&request);
                if(isout)
                {
                    record.data = request.data;
                    record.ndata = request.current;
                    bjson_json(&record, tmp);
                    fprintf(stdout, "json:%s\n", tmp);
                }
                if((ret = dbase_set_record(&db, key, &request)) < 0)
                {
                    fprintf(stderr, "set_data(%lld) ndata:%d failed, ret:%d\n", (long long)key, request.current, ret);
                    _exit(-1);
                }
                //_exit(-1);
                list[x++] = key;
            }
            if(isout)
            {
                TIMER_SAMPLE(timer);
                fprintf(stdout, "db-time-used:%lld\n", PT_LU_USEC(timer));
                TIMER_SAMPLE(timer);
            }
            if((packetid = mtask_push(&mtask, flag, block, sizeof(int64_t) * XX_PACKET_MAX)) >= 0)
            {
                if(isout)
                {
                    TIMER_SAMPLE(timer);
                    fprintf(stdout, "mtask-time-used:%lld\n", PT_LU_USEC(timer));
                    fprintf(stdout, "1:{%d:{packetid:%d}}\n", i, packetid);
                }
                ++i;
            }
            else 
            {
                fprintf(stderr, "push mtask failed, %s\n", strerror(errno));
                sleep(1);
            }
        }while(k < to);
        bjson_clean(&request);
        dbase_close(&db);
        mtask_close(&mtask);
        TIMER_CLEAN(timer);
    }
    return 0;
}
Beispiel #26
0
int main(int argc, char **argv)
{
    char *ip = NULL;
    int port = 0;
    int fd = 0;
    struct sockaddr_in sa, lsa;
    socklen_t sa_len, lsa_len = -1;
    int sock_type = 0;

    if(argc < 5)
    {
        fprintf(stderr, "Usage:%s sock_type(0/TCP|1/UDP) ip port domain\n", argv[0]);	
        _exit(-1);
    }	
    ev_sock_type = atoi(argv[1]);
    if(ev_sock_type < 0 || ev_sock_type > ev_sock_count)
    {
        fprintf(stderr, "sock_type must be 0/TCP OR 1/UDP\n");
        _exit(-1);
    }
    sock_type = ev_sock_list[ev_sock_type];
    ip = argv[2];
    port = atoi(argv[3]);
    domain = argv[4];
    /* Set resource limit */
    setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, CONN_MAX);	
    /* Initialize global vars */
    memset(events, 0, sizeof(EVENT) * CONN_MAX);
    /* Initialize inet */ 
    memset(&sa, 0, sizeof(struct sockaddr_in));	
    sa.sin_family = AF_INET;
    sa.sin_addr.s_addr = inet_addr(ip);
    sa.sin_port = htons(port);
    sa_len = sizeof(struct sockaddr);
    /* set evbase */
    if((evbase = evbase_init(0)))
    {
        TIMER_INIT(timer);
        //evbase->set_evops(evbase, EOP_POLL);
        if((fd = socket(AF_INET, sock_type, 0)) > 0)
        {
            /* Connect */
            if(connect(fd, (struct sockaddr *)&sa, sa_len) == 0 )
            {
                /* set FD NON-BLOCK */
                fcntl(fd, F_SETFL, O_NONBLOCK);
                if(sock_type == SOCK_STREAM)
                {
                    event_set(&events[fd], fd, E_READ|E_WRITE|E_PERSIST, 
                            (void *)&events[fd], &ev_handler);
                }
                else
                {
                    event_set(&events[fd], fd, E_READ|E_WRITE|E_PERSIST, 
                            (void *)&events[fd], &ev_udp_handler);
                }
                evbase->add(evbase, &events[fd]);
                sprintf(buffer[fd], "%d:client message\r\n", fd);
                lsa_len = sizeof(struct sockaddr);
                memset(&lsa, 0, lsa_len);
                getsockname(fd, (struct sockaddr *)&lsa, &lsa_len);
                SHOW_LOG("Connected to %s:%d via %d port:%d", ip, port, fd, ntohs(lsa.sin_port));
            }
            else
            {
                FATAL_LOG("Connect to %s:%d failed, %s", ip, port, strerror(errno));
                _exit(-1);
            }
        }
        while(1)
        {
            evbase->loop(evbase, 0, NULL);
            usleep(10);
        }
        //TIMER_CLEAN(timer);
    }
    return -1;
}
 * Hold off watchdog timer
 *
 * @v retry		Retry timer
 * @v over		Failure indicator
 */
static void efi_watchdog_expired ( struct retry_timer *timer,
				   int over __unused ) {
	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
	static CHAR16 data[] = WATCHDOG_DATA;
	EFI_STATUS efirc;
	int rc;

	DBGC2 ( timer, "EFI holding off watchdog timer\n" );

	/* Restart this holdoff timer */
	start_timer_fixed ( timer, ( WATCHDOG_HOLDOFF_SECS * TICKS_PER_SEC ) );

	/* Reset watchdog timer */
	if ( ( efirc = bs->SetWatchdogTimer ( WATCHDOG_TIMEOUT_SECS,
					      WATCHDOG_CODE, sizeof ( data ),
					      data ) ) != 0 ) {
		rc = -EEFI ( efirc );
		DBGC ( timer, "EFI could not set watchdog timer: %s\n",
		       strerror ( rc ) );
		return;
	}
}

/** Watchdog holdoff timer */
struct retry_timer efi_watchdog = TIMER_INIT ( efi_watchdog_expired );
Beispiel #28
0
int main(int argc, char **argv)
{
    int i = 0;

    if(argc < 7)
    {
        fprintf(stderr, "Usage:%s sock_type(0/TCP|1/UDP) iskeepalive ip port concurrecy limit\n", argv[0]);	
        _exit(-1);
    }	
    ev_sock_type = atoi(argv[1]);
    if(ev_sock_type < 0 || ev_sock_type > ev_sock_count)
    {
        fprintf(stderr, "sock_type must be 0/TCP OR 1/UDP\n");
        _exit(-1);
    }
    sock_type = ev_sock_list[ev_sock_type];
    keepalive = atoi(argv[2]);
    ip = argv[3];
    port = atoi(argv[4]);
    conn_num = atoi(argv[5]);
    limit = atoi(argv[6]);
    TIMER_INIT(timer);
    /* Set resource limit */
    setrlimiter("RLIMIT_NOFILE", RLIMIT_NOFILE, CONN_MAX);	
    /* Initialize global vars */
    if((conns = (CONN *)calloc(CONN_MAX, sizeof(CONN))))
    {
        //memset(events, 0, sizeof(EVENT *) * CONN_MAX);
        /* Initialize inet */ 
        memset(&xsa, 0, sizeof(struct sockaddr_in));	
        xsa.sin_family = AF_INET;
        xsa.sin_addr.s_addr = inet_addr(ip);
        xsa.sin_port = htons(port);
        xsa_len = sizeof(struct sockaddr);
        /* set evbase */
        if((evbase = evbase_init(0)))
        {
            if(is_use_ssl)
            {
#ifdef USE_SSL
                SSL_library_init();
                OpenSSL_add_all_algorithms();
                SSL_load_error_strings();
                if((ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
                {
                    ERR_print_errors_fp(stdout);
                    _exit(-1);
                }
#endif
            }
            for(i = 0; i < conn_num; i++)
            {
                new_request();
                i++;
            }
            running_status = 1;
            do
            {
                evbase->loop(evbase, 0, NULL);
                //usleep(1000);
            }while(running_status);
            for(i = 0; i < CONN_MAX; i++)
            {
                if(conns[i].fd > 0)
                {
                    event_destroy(&conns[i].event);
                    shutdown(conns[i].fd, SHUT_RDWR);
                    close(conns[i].fd);
#ifdef USE_SSL
                    if(conns[i].ssl)
                    {
                        SSL_shutdown(conns[i].ssl);
                        SSL_free(conns[i].ssl); 
                    }
#endif
                }
            }
#ifdef USE_SSL
            ERR_free_strings();
            SSL_CTX_free(ctx);
#endif
        }
        free(conns);
        TIMER_CLEAN(timer);
    }
    return -1;
}
Beispiel #29
0
int main(int argc, char **argv)
{
    unsigned char url[HTTP_URL_MAX], *p = NULL;
    FILE *fp = NULL;
    unsigned char  key[MD5_LEN];
    void *urlmap = NULL, *dp = NULL, *olddp = NULL;
    long n = 0, id = 0;
    void *timer = NULL;
    long long total = 0;
    char *file = NULL;

    if(argc < 2)
    {
        fprintf(stderr, "Usage:%s file\n", argv[0]);
        _exit(-1);
    }
    file = argv[1];
    if(file && (fp = fopen(file, "r")))
    {
        KVMAP_INIT(urlmap);
        if(urlmap)
        {
            TIMER_INIT(timer);
            while(fgets((char *)url, HTTP_URL_MAX, fp))
            {
                //fprintf(stdout, "%s", url);
                //memset(url, 0, HTTP_URL_MAX);
                //continue;
                //continue;
                p = url;
                while(*p != '\0' && *p != '\r' && *p != '\n') ++p;
                n = p - url;
                //n = strlen(url) - 1;
                //if(n == 0) {fprintf(stdout, "URL:%d\n", id); continue;}
                md5(url, n, key);
                dp = (void *)++id;
                olddp = NULL;
                TIMER_SAMPLE(timer);
                KVMAP_ADD(urlmap, key, dp, olddp);
                TIMER_SAMPLE(timer);
                total += PT_LU_USEC(timer);
                if(olddp)
                {
                    fprintf(stdout, "Repeat:%ld vs %ld:%d:%s\n", 
                            (long)dp, (long)olddp, n, url);
                }
                else
                {
                    //fprintf(stdout, "%ld:%s", id, url);
                }
                memset(url, 0, HTTP_URL_MAX);
            }
            if(id > 0)
            {
                fprintf(stdout, "add %d sizeof(KVNODE):%d avg:%g microsecond(s)\n", 
                        id, sizeof(KVNODE), (double )(total/id));
            }
            TIMER_CLEAN(timer);
            KVMAP_CLEAN(urlmap);
        }
        fclose(fp);
    }
    while(1) sleep(1);
}
void BuildsWindow::Initialize() {
	ToolboxPanel::Initialize();
	Resources::Instance().LoadTextureAsync(&texture, Resources::GetPath("img/icons", "list.png"), IDB_Icon_list);
	send_timer = TIMER_INIT();
}