void LicenseDialog::updateSize() { QTextStream qout(stdout); QSize screenSize; int wscreen; int hscreen; int width = 640; int height = 700; screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()) .size(); wscreen = screenSize.width(); hscreen = screenSize.height(); width = TSMIN(width, wscreen); height = TSMIN(height, hscreen); setGeometry(wscreen / 2 - width / 2, hscreen / 2 - height / 2, width, height); setFixedWidth(width); setFixedHeight(height); }
void TraceAnalyzer::colorizeTasks() { unsigned int cpu; double nf; int n; int ncolor; double s; int step; int red; int green; int blue; struct drand48_data rdata; int i, j; QList<TColor> colorList; const TColor black(0, 0, 0); const TColor white(255, 255, 255); TColor gray; TColor tmp; long int rnd = 0; srand48_r(290876, &rdata); for (cpu = 0; cpu <= getMaxCPU(); cpu++) { DEFINE_CPUTASKMAP_ITERATOR(iter) = cpuTaskMaps[cpu].begin(); while (iter != cpuTaskMaps[cpu].end()) { CPUTask &task = iter.value(); iter++; if (colorMap.contains(task.pid)) continue; TColor color; colorMap.insert(task.pid, color); } } n = colorMap.size(); nf = (double) n; s = 0.95 * cbrt( (1 / nf) * (255 * 255 * 255 )); s = TSMIN(s, 128.0); s = TSMAX(s, 1.0); retry: step = (int) s; for (red = 0; red < 256; red += step) { for (green = 0; green < 256; green += step) { for (blue = 0; blue < 256; blue += step) { TColor color(red, green, blue); if (color.SqDistance(black) < 10000) continue; if (color.SqDistance(white) < 12000) continue; gray = TColor(red, red, red); if (color.SqDistance(gray) < 2500) continue; colorList.append(color); } } } ncolor = colorList.size(); if (ncolor < n) { s = s * 0.95; if (s >= 1) { colorList.clear(); vtl::warnx("Retrying colors in %s:%d\n", __FILE__, __LINE__); goto retry; } } /* * Randomize the order by swapping every element with a random * element */ for (i = 0; i < ncolor; i++) { lrand48_r(&rdata, &rnd); j = rnd % ncolor; tmp = colorList[j]; colorList[j] = colorList[i]; colorList[i] = tmp; } i = 0; DEFINE_COLORMAP_ITERATOR(iter) = colorMap.begin(); while (iter != colorMap.end()) { TColor &color = iter.value(); iter++; color = colorList.at(i % ncolor); i++; } }
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; }