コード例 #1
0
ファイル: simulation.c プロジェクト: gsmadhusudan/Balsa
void Simulation_Run (void)
{
    GrayControlIcons (FALSE, TRUE, FALSE);
    if (pipe (breezesim_pipe) < 0) {
      perror("pipe");
      exit(1);
    }

    breezesimPid = fork ();
    if (breezesimPid == 0)
    {
        signal (SIGCHLD, NULL);

        close (3);
        dup2 (breezesim_pipe[0], 3);

        // char *command = g_strdup_printf ("breeze-sim --ctrl-pipe %s%s--tracefile=%s.hhh %s", (traceType==TraceAllChans)?"--traceallchans ":"", (traceType==TraceNamedPortsOnly)?"--tracenamedportsonly ":"", projectName, projectName);
        //printf ("Launching %s\n", command);
        char *tracefilearg = g_strdup_printf ("--tracefile=%s.hhh", projectName);

#define BREEZESIM_MAX_ARGS 10   /* This doesn't include the arguments passed from the command-line of breeze-sim-ctrl to breeze-sim */

        char **argv = g_new0 (char *, breezesim_passedArgCount + BREEZESIM_MAX_ARGS);
        int argc = 0;

        argv[argc++] = "breeze-sim";
        argv[argc++] = "--ctrl-pipe";

        switch (getTraceType ())
        {
        case TraceAllChans:
            argv[argc++] = "--traceallchans";
            break;
        case TracePortsOnly:
            break;
            //        case TraceNamedPortsOnly:
            //            argv[argc++] = "--tracenamedportsonly";
            //            break;
        }

        memcpy (argv + argc, breezesim_passedArgs, breezesim_passedArgCount * sizeof (char *));
        argc += breezesim_passedArgCount;
        argv[argc++] = tracefilearg;
        argv[argc++] = projectName;
        argv[argc++] = NULL;

/*
        int i = 0;
        while (argv[i])
        {
            fprintf (stderr, "argv[%d]=%s.\n", i, argv[i]);
            i++;
        }
*/
        execvp ("breeze-sim", argv);
    }
コード例 #2
0
void TraceAnalyzer::threadProcess()
{
	parser->waitForTraceType();
	events = parser->getEventsTList();
	switch (getTraceType()) {
	case TRACE_TYPE_FTRACE:
		processFtrace();
		break;
	case TRACE_TYPE_PERF:
		processPerf();
		break;
	default:
		return;
	}
	processSchedAddTail();
	processFreqAddTail();
}
コード例 #3
0
bool TraceAnalyzer::exportTraceFile(const char *fileName, int *ts_errno,
				    exporttype_t export_type)
{
	bool isFtrace = false, isPerf = false;
	char *wbuf, *wb;
	int fd, w;
	int written, written_io, space, nrspaces, write_rval;
	int nr_elements;
	int idx;
	int i;
	const TraceEvent *eptr;
	bool rval = true;
	const char *ename;
	char tbuf[40];
	event_t cpuevent_type = (event_t) 0;
	bool ok;
	bool filtered = isFiltered();

	nr_elements = filtered ? filteredEvents.size() : events->size();
	*ts_errno = 0;

	if (!isOpen()) {
		*ts_errno = - TS_ERROR_INTERNAL;
		return false;
	}

	switch (getTraceType()) {
	case TRACE_TYPE_FTRACE:
		isFtrace = true;
		break;
	case TRACE_TYPE_PERF:
		isPerf = true;
		break;
	default:
		*ts_errno = - TS_ERROR_INTERNAL;
		return false;
	}

	wbuf = (char*) mmap(nullptr, (size_t) WRITE_BUFFER_SIZE,
			    PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
			    -1, 0);

	if (wbuf == MAP_FAILED)
		mmap_err();

	if (!parser->traceFile->isIntact(ts_errno)) {
		rval = false;
		if (*ts_errno == 0)
			*ts_errno = - TS_ERROR_FILECHANGED;
		goto error_munmap;
	}

	parser->traceFile->allocMmap();
	fd =  clib_open(fileName, O_WRONLY | O_CREAT,
			(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));

	if (fd < 0) {
		rval = false;
		*ts_errno = errno;
		goto error_munmap;
	}

	idx = 0;

	if (export_type == EXPORT_TYPE_CPU_CYCLES) {
		cpuevent_type = determineCPUEvent(ok);
		if (!ok) {
			rval = false;
			*ts_errno = - TS_ERROR_NOCPUEV;
			goto error_close;
		}
	}

	if (!isPerf)
		goto skip_perf;

	do {
		written = 0;
		space = WRITE_BUFFER_SIZE;
		wb = wbuf;

		while (idx < nr_elements && written < WRITE_BUFFER_LIMIT) {
			if (filtered)
				eptr = filteredEvents[idx];
			else
				eptr = &(*events)[idx];
			idx++;
			if (export_type == EXPORT_TYPE_CPU_CYCLES &&
			    eptr->type != cpuevent_type)
				continue;
			eptr->time.sprint(tbuf);
			w = snprintf(wb, space,
				     "%s %5u [%03u] %s: ",
				     eptr->taskName->ptr, eptr->pid,
				     eptr->cpu, tbuf);
			if (w > 0) {
				written += w;
				space   -= w;
				wb      += w;
			}
			if (eptr->intArg != 0) {
				w = snprintf(wb, space, "%10u ",
					     eptr->intArg);
				if (w > 0) {
					written += w;
					space   -= w;
					wb      += w;
				}
			}

			ename = eptr->getEventName()->ptr;
			nrspaces = TSMAX(1, spaceStrLen - strlen(ename));
			nrspaces = TSMIN(nrspaces, space);
			if (nrspaces > 0) {
				strncpy(wb, spaceStr, nrspaces);
				written += nrspaces;
				space   -= nrspaces;
				wb      += nrspaces;
			}

			w = snprintf(wb, space, "%s:", ename);
			if (w > 0) {
				written += w;
				space   -= w;
				wb      += w;
			}

			for (i = 0; i < eptr->argc; i++) {
				w = snprintf(wb, space, " %s",
					     eptr->argv[i]->ptr);
				if (w > 0) {
					written += w;
					space   -= w;
					wb      += w;
				}
			}
			w = snprintf(wb, space, "\n");
			if (w > 0) {
				written += w;
				space   -= w;
				wb      += w;
			}
			if (eptr->postEventInfo != nullptr &&
			    eptr->postEventInfo->len > 0) {
				size_t cs = TSMIN(space,
						  eptr->postEventInfo->len);
				parser->traceFile->readChunk(
					eptr->postEventInfo, wb, space,
					ts_errno);
				if (*ts_errno != 0) {
					rval = false;
					goto error_close;
				}
				if (cs > 0) {
					written += cs;
					space   -= cs;
					wb      += cs;
				}
			}
		}

		if (written > 0) {
			written_io = 0;
			do {
				write_rval = write(fd, wbuf, written);
				if (write_rval > 0) {
					written_io += write_rval;
				}
				if (write_rval < 0 && errno != EINTR) {
					rval = false;
					*ts_errno = errno;
					goto error_close;
				}
			} while(written_io < written);
		}
		if (idx >= nr_elements)
			break;
	} while(true);

	if (!parser->traceFile->isIntact(ts_errno)) {
		rval = false;
		if (*ts_errno == 0)
			*ts_errno = - TS_ERROR_FILECHANGED;
		goto error_close;
	}

skip_perf:
	if (!isFtrace)
		goto skip_ftrace;

/* Insert ftrace code here */

skip_ftrace:
error_close:
	if (clib_close(fd) != 0) {
		if (errno != EINTR) {
			rval = false;
			*ts_errno = errno;
		}
	}

error_munmap:
	parser->traceFile->freeMmap();
	if (munmap(wbuf, WRITE_BUFFER_SIZE) != 0)
		munmap_err();

	return rval;
}
コード例 #4
0
int
getTraceType_i ()
{
  return getTraceType ();
}