コード例 #1
0
ファイル: nlmon.c プロジェクト: el8/nlmon
static void measure_one_cycle(void)
{
	struct timespec ts1, ts2, delta, sleep;
	int rc;

	current_sum_utime = 0;
	current_sum_stime = 0;
	current_sum_cpu_utime = 0;
	current_sum_cpu_stime = 0;

	if (nr_cycles)
		output->print_cycle_start();
	else
		output->print_sync();
	new_cycle = 1;

	rc = clock_gettime(CLOCK_MONOTONIC, &ts1);
	if (rc < 0)
		DIE_PERROR("clock_gettime failed");

	query_tasks();
	query_memory();
	query_cpus(opt_all_cpus);

	print_tasks();
	print_memory();
	print_cpus(opt_all_cpus);

	rc = clock_gettime(CLOCK_MONOTONIC, &ts2);
	if (rc < 0)
		DIE_PERROR("clock_gettime failed");

	timespec_delta(&ts1, &ts2, &delta);
	if (nr_cycles)
		output->print_cycle_end(&delta);

	/* check if we can meet the target measurement interval */
	if (delta.tv_sec > target.tv_sec ||
	    (delta.tv_sec == target.tv_sec && delta.tv_nsec > target.tv_nsec)) {
		output->exit_output();
		DIE("Target measurement intervall too small. Current overhead: %u seconds %lu ms\n",
			(int) delta.tv_sec, delta.tv_nsec / NSECS_PER_MSEC);
	}

	/* now go sleeping for the rest of the measurement interval */
	if (nr_cycles)
		timespec_delta(&delta, &target, &sleep);
	else
		timespec_delta(&delta, &ts_sync, &sleep);

	wait_for_cycle_end(&sleep);
	nr_cycles++;
}
コード例 #2
0
ファイル: job_parse.cpp プロジェクト: YangJinWen/openflow
bool CJobParse::parse_job(const int32_t job_id
                          , std::list<std::list<openflow::task_info*>*>& job_tasks)
{
    openflow::job_info job_info;
    if (!fetch_job(job_id, job_info))
    {
        LOG(ERROR) << "cant't get this job: " << job_id;
        return false;
    }
    boost::property_tree::ptree pt;
    boost::property_tree::ptree root;

    std::stringstream ss;
    ss << job_info.xml_desc;
    boost::property_tree::xml_parser::read_xml(ss, pt);
    root = pt.get_child("job");

    common::CSqliteHelp& db_help =
                boost::serialization::singleton<common::CSqliteHelp>::get_mutable_instance();
    /*
       const std::string task_member[] = {"name","description","nodes", "command"};
       std::vector<StTask> tasks;
       StTask task;
    */
    const std::string task_member[] = {"name","description","nodes", "command"};


    int id = 1;
    for(boost::property_tree::ptree::iterator it = root.begin(); it != root.end(); it++)
    {
        if(it->first == "shell_process")
        {
            std::list<openflow::task_info*> *task_list = new std::list<openflow::task_info*>;
            openflow::task_info *task =  new openflow::task_info;
            boost::property_tree::ptree pt;
            std::string val;
            boost::property_tree::ptree shell_process = it->second;
            int i=0;
            for(; i < 4; i++)
            {
                pt = shell_process.get_child(task_member[i]);
                val = pt.data();
                LOG(INFO) << "XML elemnets: " << val;

                switch(i)
                {
                case 0:
                    task->name = val;
                    break;
                case 1:
                    task->description = val;
                    break;
                case 2:
                    task->nodes = val;
                    break;
                case 3:
                    task->cmd = val;
                    break;
                }
            }

            //FIXME 临时测试,兼容之前task_info结构体
            task->uuid = common::CUtils::generate_uuid();
            task->job_id = job_id;
            task->task_id = id;
            task->task_name = task->name;
            id++;

            task_list->push_back(task);

            //任务入库
            std::string sql = boost::str(boost::format(
                    "INSERT INTO TaskState (job_id,task_id,task_name,cmd,desc) values('%d','%d','%s','%s','%s');")
                % job_id % task->task_id % task->task_name % task->cmd % task->description);
            if(!db_help.update(sql)) {
                LOG(ERROR) << "execut inert task sql error: " << sql;
                return false;
            }

            job_tasks.push_back(task_list);
        }
    }

    print_tasks(job_tasks);

    return true;
}
コード例 #3
0
ファイル: t_tasks.c プロジェクト: pete/freenote-probe
int main(void)
{
	task_t task = { VALID_TASK_MAGIC,
			TODO, 
			ICMP, 
			4839903, 
			COND_SUCCESS,
			1, 
			0,
			"4.131.153.3", 
			900913,
			1337,
			42,
			{ 0 },
			{0, 0},
			{0, 0},
			{0, 0},
			{0, 0},
			{0, 0},
			{0, 0},
			{0, 0}
			};
	int i;

	task.ip_addr.s_addr = inet_addr("4.131.153.3");

	printf("Size of a single task:  %d bytes.\n", sizeof(task_t));

	printf("Initializing task stack...\n");
	tasks_init();
	
	printf("Now let's add a task.\n");
	i = task_add(task);
	printf("task_add returned %d.\n", i);

	printf("Let's print the tasks:\n");
	print_tasks();

	printf("Get a task to perform...\n");
	i = get_task(&task);
	printf("get_task returned %d.\n", i);

	printf("Did get_task change the status properly?\n");
	print_tasks();

	printf("Pretend to be working for 1 second...\n");
	sleep(1);

	printf("Now let's tell it that we're done with the task.\n");
	i = task_set_status(task.taskid, COMPLETE);
	printf("task_set status returned %d.\n", i);
	print_tasks();

	printf("get_completed\n");
	i = get_completed(&task);
	printf("%d\n", i);
	print_tasks();

	return 0;

}
コード例 #4
0
ファイル: gpio_trace.c プロジェクト: 119/bcm-wiced-sdk
/**
 * Start tracing scheduler activity.
 */
void gpio_trace_start_trace( trace_flush_function_t flush_f )
{
    /* We don't need a flush function because GPIO tracing does not use "any" memory */
    UNUSED_PARAMETER( flush_f );

    /* Setup the GPIO pins and construct the bit list. */
    gpio_trace_init( );

    /* Print out the GPIO->Bit mapping. */
    Bit_List *curr = least_significant_bit;
    unsigned int i = 0;
    while ( curr != NULL )
    {
#if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED
    #define _GPIO_TRACE_START_TRACE_TEXT    "Bit"
#elif TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ONEBIT
    #define _GPIO_TRACE_START_TRACE_TEXT    "Task"
#endif /* #if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED */
        printf( _GPIO_TRACE_START_TRACE_TEXT " %d => Pin %d\r\n", i, breakout_pins_get_pin_number( curr->settings ) );
        curr = curr->next;
        i++;
    }

    printf( "\r\n" );
    print_tasks( );

#if 0 /* TEST SEQUENCE */
    /* Count the number of GPIO pins available */
    int num_pins = 0;
    curr = least_significant_bit;
    while ( curr != NULL )
    {
        num_pins++;
        curr = curr->next;
    }

    printf( "\r\n" );
    printf( "Testing in 3 seconds..." );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting in 2 seconds..." );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting in 1 second... " );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting...             " );

#if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED
#include <math.h>
    const int max_value = (int) pow( (double) 2, (double) num_pins );
#elif TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ONEBIT
    const int max_value = num_pins;
#endif /* #if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED */
    for ( i = 0; i < max_value; i++ )
    {
        gpio_encode_value( i );
        host_rtos_delay_milliseconds( 1 );
    }

    gpio_encode_value( all_off );
    printf( "\rTesting... DONE!       \r\n" );
#endif /* 0 */

    /* Flash GPIO pins to indicate start of trace */
    TRACE_START_SEQUENCE( );
} /* gpio_trace_start_trace */