VOS_UINT16 OS_GetTaskIdList(int iTaskIdList[], int iTaskMaxNum)
{
    VOS_UINT16              usTaskNum   = (VOS_UINT16)iTaskMaxNum;

    if (VOS_NULL_PTR == iTaskIdList)
    {
        return VOS_NULL;
    }

#if ((VOS_VXWORKS == VOS_OS_VER) || (VOS_NUCLEUS == VOS_OS_VER) || (VOS_WIN32 == VOS_OS_VER))
    usTaskNum = (VOS_UINT16)taskIdListGet(iTaskIdList, usTaskNum);
#elif (VOS_RTOSCK == VOS_OS_VER)
    if (SRE_OK != SRE_TaskIDList((UINT16 *)&usTaskNum, (UINT32 *)iTaskIdList))
    {
        return VOS_NULL;
    }
#else
    return VOS_NULL;
#endif

    return usTaskNum;
}
void cpu_view_report_init(void)
{
    u32     i;
    WIND_TCB     *tempPtr;
    u32         startslice = 0;
    /*establish  map between task and stat info */
    g_task_num = (u32)taskIdListGet( vxworks_tid_list, BSP_OM_MAX_TASK_NUM );
    if (0 == g_task_num)
    {
        return;
    }

    for ( i=0; i<g_task_num; i++ )
    {
        tempPtr = (WIND_TCB *)((u32)vxworks_tid_list[i]);
        tempPtr->spare4 = (int)i;
        strncpy((char *)g_om_cpu_trace[i].task_name, (const char *)taskName(vxworks_tid_list[i]), BSP_SYSVIEW_TASK_NAME_LEN);
        g_om_cpu_trace[i].slices = 0;
        g_om_cpu_trace[i].max_slice = 0;
        g_om_cpu_trace[i].min_slice = 0xffffffff;
    }

    /*Init Task/interrupt Switch Hook*/
    if ( ERROR == taskSwitchHookAdd( (FUNCPTR)cpu_task_swt_hook ) )
    {
        printf("CPU_utilization_Init fail.\r\n");
        return;
    }

    startslice = om_timer_get();

    old_slice = startslice;

    cpu_state = 1;

    return;
}
Beispiel #3
0
STATUS taskShow
    (
    int tid,		/* task ID */
    int level		/* 0 = summary, 1 = details, 2 = all tasks */
    )
    {
    FAST int	nTasks;			/* number of task */
    FAST int	ix;			/* index */
    TASK_DESC	td;			/* task descriptor for task info */
    WIND_TCB *	pTcb;			/* pointer to tasks tcb */
    int		idList[MAX_DSP_TASKS];	/* list of active IDs */
    char	optionsString[256];	/* task options string */

    tid = taskIdDefault (tid);				/* get default task */

    switch (level)
	{
	case 0 :					/* summarize a task */
	    {
	    if (taskInfoGet (tid, &td) != OK)
		{
		printErr ("Task not found.\n");
		return (ERROR);
		}

	    printf (infoHdr);
	    taskSummary (&td);
	    break;
	    }

	case 1 :					/* get task detail */
	    {
	    if (taskInfoGet (tid, &td) != OK)
		{
		printErr ("Task not found.\n");
		return (ERROR);
		}

	    taskOptionsString (tid, optionsString);	/* get options string */

	    /* Print the summary as in all_task_info, then all the regs. */

	    printf (infoHdr);				/* banner */
	    taskSummary (&td);

	    printf ("\nstack: base 0x%-6x  end 0x%-6x  size %-5d  ",
		    (int)td.td_pStackBase, (int)td.td_pStackEnd,
		    td.td_stackSize);

	    if (td.td_options & VX_NO_STACK_FILL)
		printf ("high %5s  margin %5s\n", "???", "???");
	    else
		printf ("high %-5d  margin %-5d\n", td.td_stackHigh,
			 td.td_stackMargin);

	    printf ("\noptions: 0x%x\n%s\n", td.td_options, optionsString);

	    /* display VxWorks events information */

	    eventTaskShow (&td.td_events);

	    if (tid != taskIdSelf ())			/* no self exam */
		{
		taskRegsShow (tid);
		if (_func_fppTaskRegsShow != NULL)	/* fp regs if attached*/
		    (* _func_fppTaskRegsShow) (tid);
		if (_func_dspTaskRegsShow != NULL)	/* dsp regs if attached*/
		    (* _func_dspTaskRegsShow) (tid);
#ifdef _WRS_ALTIVEC_SUPPORT
		if (_func_altivecTaskRegsShow != NULL)	/* altivec regs if attached*/
		    (* _func_altivecTaskRegsShow) (tid);
#endif /* _WRS_ALTIVEC_SUPPORT */

#if (CPU_FAMILY==I80X86)
		if (_func_sseTaskRegsShow != NULL)	/* SIMD regs if attached */
		    (* _func_sseTaskRegsShow) (tid);
#endif /* (CPU_FAMILY==I80X86) */
		}

	    /* print exception info if any */

	    if ((_func_excInfoShow != NULL) && ((pTcb = taskTcb (tid)) != NULL))
		(* _func_excInfoShow) (&pTcb->excInfo, FALSE);
	    break;
	    }

	case 2 :				/* summarize all tasks */
	default :
	    {
	    printf (infoHdr);

	    nTasks = taskIdListGet (idList, NELEMENTS (idList));
	    taskIdListSort (idList, nTasks);

	    for (ix = 0; ix < nTasks; ++ix)
		{
		if (taskInfoGet (idList [ix], &td) == OK)
		    taskSummary (&td);
		}
	    break;
	    }
	}

    return (OK);
    }
static void command_get_children(char * token, Channel * c) {
    char id[256];
    int attached_only;

    json_read_string(&c->inp, id, sizeof(id));
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    attached_only = json_read_boolean(&c->inp);
    if (read_stream(&c->inp) != 0) exception(ERR_JSON_SYNTAX);
    if (read_stream(&c->inp) != MARKER_EOM) exception(ERR_JSON_SYNTAX);

    write_stringz(&c->out, "R");
    write_stringz(&c->out, token);

    if (id[0] != 0) {
        write_errno(&c->out, 0);
        write_stringz(&c->out, "null");
    }
    else {
#if defined(WIN32)
    DWORD err = 0;
    HANDLE snapshot;
    PROCESSENTRY32 pe32;

    snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (snapshot == INVALID_HANDLE_VALUE) err = set_win32_errno(GetLastError());
    memset(&pe32, 0, sizeof(pe32));
    pe32.dwSize = sizeof(PROCESSENTRY32);
    if (!err && !Process32First(snapshot, &pe32)) {
        err = set_win32_errno(GetLastError());
        CloseHandle(snapshot);
    }
    write_errno(&c->out, err);
    if (err) {
        write_stringz(&c->out, "null");
    }
    else {
        int cnt = 0;
        write_stream(&c->out, '[');
        do {
            if (!attached_only || context_find_from_pid(pe32.th32ProcessID) != NULL) {
                if (cnt > 0) write_stream(&c->out, ',');
                json_write_string(&c->out, pid2id(pe32.th32ProcessID, 0));
                cnt++;
            }
        }
        while (Process32Next(snapshot, &pe32));
        write_stream(&c->out, ']');
        write_stream(&c->out, 0);
    }
    if (snapshot != INVALID_HANDLE_VALUE) CloseHandle(snapshot);
#elif defined(_WRS_KERNEL)
        int i = 0;
        int cnt = 0;
        int ids_cnt = 0;
        int ids_max = 500;
        int * ids = (int *)loc_alloc(ids_max * sizeof(int));
        for (;;) {
            ids_cnt = taskIdListGet(ids, ids_max);
            if (ids_cnt < ids_max) break;
            loc_free(ids);
            ids_max *= 2;
            ids = (int *)loc_alloc(ids_max * sizeof(int));
        }
        write_errno(&c->out, 0);
        write_stream(&c->out, '[');
        for (i = 0; i < ids_cnt; i++) {
            if (!attached_only || context_find_from_pid(ids[i]) != NULL) {
                if (cnt > 0) write_stream(&c->out, ',');
                json_write_string(&c->out, pid2id(ids[i], 0));
                cnt++;
            }
        }
        write_stream(&c->out, ']');
        write_stream(&c->out, 0);
#elif defined(__APPLE__)
#else
        DIR * proc = opendir("/proc");
        if (proc == NULL) {
            write_errno(&c->out, errno);
            write_stringz(&c->out, "null");
        }
        else {
            int cnt = 0;
            write_errno(&c->out, 0);
            write_stream(&c->out, '[');
            for (;;) {
                struct dirent * ent = readdir(proc);
                if (ent == NULL) break;
                if (ent->d_name[0] >= '1' && ent->d_name[0] <= '9') {
                    pid_t pid = atol(ent->d_name);
                    if (!attached_only || context_find_from_pid(pid) != NULL) {
                        if (cnt > 0) write_stream(&c->out, ',');
                        json_write_string(&c->out, pid2id(pid, 0));
                        cnt++;
                    }
                }
            }
            write_stream(&c->out, ']');
            write_stream(&c->out, 0);
            closedir(proc);
        }
#endif
    }

    write_stream(&c->out, MARKER_EOM);
}