Browse Source

Plan 9 from Bell Labs 2004-01-29

David du Colombier 18 years ago
parent
commit
99bf5c4cd4

+ 2 - 8
dist/replica/plan9.db

@@ -450,7 +450,7 @@
 386/bin/upas/scanmail - 775 sys sys 1073851248 127943
 386/bin/upas/send - 775 sys sys 1073851248 190699
 386/bin/upas/smtp - 775 sys sys 1073851249 271626
-386/bin/upas/smtpd - 775 sys sys 1073851250 320788
+386/bin/upas/smtpd - 775 sys sys 1075270538 320985
 386/bin/upas/spam - 775 sys sys 1064598366 36
 386/bin/upas/testscan - 775 sys sys 1064598366 82161
 386/bin/upas/token - 775 sys sys 1064598367 75930
@@ -4721,6 +4721,7 @@ sys/man/1/thesaurus - 664 sys sys 1068121775 222
 sys/man/1/time - 664 sys sys 944959673 380
 sys/man/1/touch - 664 sys sys 1018369246 461
 sys/man/1/tr - 664 sys sys 944959675 1730
+sys/man/1/trace - 664 sys sys 1075347661 1758
 sys/man/1/troff - 664 sys sys 944959675 3102
 sys/man/1/troff2html - 664 sys sys 964455062 1871
 sys/man/1/tweak - 664 sys sys 957920008 4762
@@ -10211,13 +10212,6 @@ sys/src/cmd/rio/wctl.c - 664 sys sys 1023206837 8808
 sys/src/cmd/rio/wind.c - 664 sys sys 1073268477 32704
 sys/src/cmd/rio/xfid.c - 664 sys sys 1032061723 17424
 sys/src/cmd/rm.c - 664 sys sys 1014926615 1563
-sys/src/cmd/rtstats - 20000000775 sys sys 1018897680 0
-sys/src/cmd/rtstats/edfproc.c - 664 sys sys 1055699325 3109
-sys/src/cmd/rtstats/mkfile - 664 sys sys 1038425447 425
-sys/src/cmd/rtstats/resproc.c - 664 sys sys 1037669163 2287
-sys/src/cmd/rtstats/rtstats.c - 664 sys sys 1048644563 13224
-sys/src/cmd/rtstats/time.c - 664 sys sys 1038425433 2094
-sys/src/cmd/rtstats/time.h - 664 sys sys 1038425434 164
 sys/src/cmd/rx.c - 664 sys sys 1071155928 4188
 sys/src/cmd/sam - 20000000775 sys sys 944961629 0
 sys/src/cmd/sam/address.c - 664 sys sys 944961628 3985

+ 9 - 0
dist/replica/plan9.log

@@ -13786,3 +13786,12 @@
 1075131067 0 c sys/src/cmd/ssh/scp.c - 664 sys sys 1075130172 13886
 1075185075 0 c 386/bin/scp - 775 sys sys 1075184164 151804
 1075212079 0 c sys/src/cmd/upas/smtp/greylist.c - 664 sys sys 1075211327 6300
+1075271487 0 c 386/bin/upas/smtpd - 775 sys sys 1075270538 320985
+1075348899 0 a sys/man/1/trace - 664 sys sys 1075347661 1758
+1075348899 1 d sys/src/cmd/rtstats/time.h - 664 sys sys 1038425434 0
+1075348899 2 d sys/src/cmd/rtstats/time.c - 664 sys sys 1038425433 0
+1075348899 3 d sys/src/cmd/rtstats/rtstats.c - 664 sys sys 1048644563 0
+1075348899 4 d sys/src/cmd/rtstats/resproc.c - 664 sys sys 1037669163 0
+1075348899 5 d sys/src/cmd/rtstats/mkfile - 664 sys sys 1038425447 0
+1075348899 6 d sys/src/cmd/rtstats/edfproc.c - 664 sys sys 1055699325 0
+1075348899 7 d sys/src/cmd/rtstats - 20000000775 sys sys 1018897680 0

+ 77 - 0
sys/man/1/trace

@@ -0,0 +1,77 @@
+.TH TRACE 1
+.SH NAME
+trace \- show (real-time) process behavior
+.SH SYNOPSIS
+.B trace
+[
+.B \-d
+.I profdev
+]
+[
+.B \-v
+]
+[
+.B \-w
+]
+[pid ... ]
+.SH DESCRIPTION
+.I Trace
+displays the behavior of processes running on the machine.  In its
+window it shows a time line for each traced process.  Running
+processes are shown as colored blocks.  When a process is scheduled as
+a real-time process, black up arrows indicate process releases, black
+down arrows indicate process deadlines, red down arrows indicate the
+process ran over its allotted scheduled time, and green down arrows to
+indicates a process yielded the processor before its deadline.
+Non-real-time processes do not have such release times and deadlines
+and no real-time information is shown for such processes.
+.PP
+Trace reads /proc/trace to retrieve trace events from the kernel
+scheduler.  Trace events are binary data structures, which are
+generated by the kernel scheduler whenever a noteworthy event occurs.
+The
+.B \-d
+flag can be used to specify another trace file.
+.PP
+The
+.B \-v
+flag prints out the events as they are received from the event file.
+.PP
+The \-w
+flag makes
+.B trace
+open a new window for its display.
+.PP
+To enable process tracing echo the string "trace on" into 
+/proc/<pid>/ctl.  To disable tracing of a process echo "trace off"
+in the control file.  Trace enables tracing on all processes as specified
+by their
+.B pids 
+.PP
+The following one-character commands are recognized by
+.BR trace :
+.TP
+.B +
+Zoom in by a factor of two,
+.TP
+.B -
+Zoom out by a factor of two,
+.TP
+.B p
+Pause or resume,
+.TP
+.B q
+Quit.
+.SH "SEE ALSO
+.IR proc (3)
+.SH FILES
+.TF 
+.TP
+.B /proc/trace
+trace event file
+.TP
+.B /sys/include/trace.h
+trace event data structures
+.TP
+.SH SOURCE
+.B /sys/src/cmd/trace

+ 0 - 168
sys/src/cmd/rtstats/edfproc.c

@@ -1,168 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include "realtime.h"
-#include "time.h"
-
-char *	T = "10s";
-char *	D = "5s";
-char *	C = "1.5s";
-char *	S = nil;
-char *	s = "250ms";
-char *	R = "";
-int		verbose, debug, tset, dset, cset, sset, besteffort;
-int		nproc = 1;
-
-uvlong v;
-
-char *clonedev = "#R/realtime/clone";
-char missstr[] = "sys: deadline miss: runtime";
-
-int notefd;
-int
-rthandler(void*, char *s)
-{
-	static int umpteenth;
-
-	if (!umpteenth++)
-		fprint(2, "note received: %s\n", s);
-	if (strncmp(missstr, s, strlen(missstr)) == 0)
-		return 1;
-
-	/* On any other note */
-	if (fprint(notefd, "remove") < 0)
-		sysfatal("Could not remove task: %r");
-	sysfatal("Removed task");
-	return 1;
-}
-
-static int
-schedpars(char *period, char *deadline, char *cost)
-{
-	int fd;
-
-	if ((fd = open(clonedev, ORDWR)) < 0) 
-		sysfatal("%s: %r", clonedev);
-
-	fprint(2, "T=%s D=%s C=%s procs=%d resources=%q %s%sadmit\n",
-		period, deadline, cost, getpid(), R, besteffort?"besteffort ":"", verbose?"verbose ":"");
-	if (fprint(fd, "T=%s D=%s C=%s procs=%d resources=%q %s%sadmit",
-		period, deadline, cost, getpid(), R, besteffort?"besteffort ":"", verbose?"verbose ":"") < 0)
-			sysfatal("%s: %r", clonedev);
-	notefd = fd;
-	atnotify(rthandler, 1);
-	return fd;
-}
-
-static void
-usage(void)
-{
-	fprint(2, "Usage: %s [-T period] [-D deadline] [-D cost] [-S sleepinterval] [-s sleeptime] [-R resources] [-v]\n", argv0);
-	exits(nil);
-}
-
-void
-main(int argc, char *argv[])
-{
-	Time sleepinterval;
-	Time sleeptime;
-	Time now, when;
-	int i, j, fd;
-	char *e;
-
-	quotefmtinstall();
-
-	ARGBEGIN {
-	case 'T':
-		T = EARGF(usage());
-		tset++;
-		break;
-	case 'D':
-		D = EARGF(usage());
-		dset++;
-		break;
-	case 'C':
-		C = EARGF(usage());
-		cset++;
-		break;
-	case 'S':
-		S = EARGF(usage());
-		break;
-	case 's':
-		s = EARGF(usage());
-		sset++;
-		break;
-	case 'R':
-		R = EARGF(usage());
-		break;
-	case 'n':
-		nproc = atoi(EARGF(usage()));
-		if (nproc <= 0 || nproc > 10)
-			sysfatal("%d processes?", nproc);
-		break;
-	case 'b':
-		besteffort++;
-		break;
-	case 'v':
-		verbose++;
-		break;
-	case 'd':
-		debug++;
-		break;
-	default:
-		usage();
-	}
-	ARGEND;
-
-	if (S){
-		if (e = parsetime(&sleepinterval, S))
-			sysfatal("%s: Sleep interval: %s\n", argv0, e);
-		if (e = parsetime(&sleeptime, s))
-			sysfatal("%s: Sleep time: %s\n", argv0, e);
-	}
-
-	sleeptime /= 1000000;
-	if (S && sleeptime == 0)
-		sysfatal("%s: Sleep time too small\n", argv0);
-
-	if (tset && !dset) D = T;
-
-	fd = schedpars(T, D, C);
-
-	for (j = 1; j < nproc; j++){
-		switch(fork()){
-		case -1:
-			sysfatal("fork: %r");
-		case 0:
-			fprint(2, "procs+=%d\n", getpid());
-			if (fprint(fd, "procs+=%d", getpid()) < 0)
-			sysfatal("%s: %r", clonedev);
-			for (;;){
-				for(i = 0; i < 10000; i++)
-					v+=1LL;
-				if (S){
-					now = nsec();
-					if (now >= when){
-						sleep((long)sleeptime);
-						when = now + sleepinterval;
-					}
-				}
-			}
-		default:
-			break;
-		}
-	}
-	when = nsec() + sleepinterval;
-	for (;;){
-		for(i = 0; i < 100000; i++)
-			v+=1LL;
-		if (verbose)
-			fprint(2, ".");
-		if (S){
-			now = nsec();
-			if (now >= when){
-				sleep((long)sleeptime);
-				when = now + sleepinterval;
-			}
-		}
-	}
-}

+ 0 - 30
sys/src/cmd/rtstats/mkfile

@@ -1,30 +0,0 @@
-</$objtype/mkfile
-
-INCLUDES=-I/sys/src/9/port
-CFLAGS=$CFLAGS $INCLUDES
-
-TARG=rtstats
-
-BIN=/$objtype/bin
-
-OFILES = \
-	rtstats.$O\
-	time.$O
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${OFILES:%.$O=%.c}\
-	edfproc.c resproc.c\
-	${TARG:%=/386/bin/%}\
-
-</sys/src/cmd/mkone
-
-$O.edfproc:	edfproc.$O time.$O
-	$LD -o $O.edfproc edfproc.$O time.$O
-
-$O.resproc:	resproc.$O time.$O
-	$LD -o $O.resproc resproc.$O time.$O
-
-dep:
-	mkdep $INCLUDES $CFILES

+ 0 - 112
sys/src/cmd/rtstats/resproc.c

@@ -1,112 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include "time.h"
-
-int		T = 201;
-int		D = 179;
-int		C = 11;
-int		verbose, debug, tset, dset, cset, sset;
-int		nproc = 1;
-int		umpteenth;
-char *resources = "a 4ms";
-
-uvlong v;
-uvlong onems;
-
-char *clonedev = "#R/realtime/clone";
-char missstr[] = "sys: deadline miss: runtime";
-
-int notefd;
-int
-rthandler(void*, char *s)
-{
-	umpteenth++;
-	if (strncmp(missstr, s, strlen(missstr)) == 0)
-		return 1;
-
-	fprint(2, "note received: %s\n", s);
-	/* On any other note */
-	if (fprint(notefd, "remove") < 0)
-		sysfatal("Could not remove task: %r");
-	sysfatal("Removed task");
-	return 1;
-}
-
-static void
-usage(void)
-{
-	fprint(2, "Usage: %s [-T period] [-D deadline] [-D cost] [-v] [resource...]\n", argv0);
-	exits(nil);
-}
-
-void
-main(int argc, char *argv[])
-{
-	int fd;
-
-	quotefmtinstall();
-
-	ARGBEGIN {
-	case 'T':
-		T = strtoul(EARGF(usage()), nil, 0);
-		tset++;
-		break;
-	case 'D':
-		D = strtoul(EARGF(usage()), nil, 0);
-		dset++;
-		break;
-	case 'C':
-		C = strtoul(EARGF(usage()), nil, 0);
-		cset++;
-		break;
-	case 'v':
-		verbose++;
-		break;
-	case 'd':
-		debug++;
-		break;
-	default:
-		usage();
-	}
-	ARGEND;
-
-	if ((fd = open(clonedev, ORDWR)) < 0) 
-		sysfatal("%s: %r", clonedev);
-	fprint(2, "T=%dms D=%dms C=%dms procs=self  admit\n", 100, 100, 10);
-	notefd = fd;
-	atnotify(rthandler, 1);
-	if (fprint(fd, "T=%dms D=%dms C=%dms procs=self admit", 100, 100, 10) < 0)
-			sysfatal("%s: %r", clonedev);
-	while(umpteenth ==0)
-		v+=1LL;
-	if (fprint(fd, "expel") < 0)
-		sysfatal("%s: expel: %r", clonedev);
-	onems = v/10;
-	if (verbose)
-		print("One millisecond is %llud cycles\n", v);
-
-	if (tset && !dset) D = T;
-
-	fprint(2, "T=%dms D=%dms C=%dms procs=%d resources=%q %sadmit\n",
-		T, D, C, getpid(), resources, verbose?"verbose ":"");
-	notefd = fd;
-	atnotify(rthandler, 1);
-	if (fprint(fd, "T=%dms D=%dms C=%dms procs=%d resources=%q %sadmit",
-		T, D, C, getpid(), resources, verbose?"verbose ":"") < 0)
-			sysfatal("%s: %r", clonedev);
-
-	for (;;){
-		if (fprint(fd, "acquire=a") < 0)
-			sysfatal("%s: acquire=a: %r", clonedev);
-		v = 3*onems;
-		while(v != 0LL)
-			v -= 1LL;
-		if (fprint(fd, "release=a") < 0)
-			sysfatal("%s: release=a: %r", clonedev);
-		v = 5*onems;
-		while(v != 0LL)
-			v -= 1LL;
-		if (fprint(fd, "yield") < 0)
-			sysfatal("%s: yield a: %r", clonedev);
-	}
-}

+ 0 - 583
sys/src/cmd/rtstats/rtstats.c

@@ -1,583 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <thread.h>
-#include <ip.h>
-#include <bio.h>
-#include <stdio.h>
-#include <draw.h>
-#include <mouse.h>
-#include <cursor.h>
-#include <keyboard.h>
-#include "realtime.h"
-#include "time.h"
-
-char *T = "200ms";
-char *Dl = "80ms";
-char *C = "40ms";
-
-#define numblocks(a, b)	(((a) + (b) - 1) / (b))
-#define roundup(a, b)	(numblocks((a), (b)) * (b))
-
-typedef struct {
-	ulong		tid;
-	char			*settings;
-	int			nevents;	
-	Schedevent	*events;
-} Task;
-
-enum {
-	Nevents = 1000,
-	Ncolor = 6,
-	K = 1024,
-	STACKSIZE = 8 * K,
-};
-
-char	*taskdir = "#R/realtime/task";
-char	*clonedev = "#R/realtime/clone";
-char	*profdev = "#R/realtime/nblog";
-char	*timedev = "#R/realtime/time";
-Time	prevts;
-
-int	newwin;
-int	Width = 1000;		
-int	Height = 100;		// Per task
-int	topmargin = 8;
-int	bottommargin = 4;
-int	lineht = 12;
-
-Schedevent *event;
-
-void drawrt(void);
-int schedparse(char*, char*, char*);
-
-static char *schedstatename[] = {
-	[SRelease] =	"Release",
-	[SRun] =		"Run",
-	[SPreempt] =	"Preempt",
-	[SBlock] =		"Block",
-	[SResume] =	"Resume",
-	[SDeadline] =	"Deadline",
-	[SYield] =		"Yield",
-	[SSlice] =		"Slice",
-	[SExpel] =		"Expel",
-};
-
-static int ntasks, besteffort, verbose;
-static Task *tasks;
-static Image *cols[Ncolor][3];
-static Font *mediumfont, *tinyfont;
-static Image *grey, *red, *green, *bg, *fg;
-char missstr[] = "sys: deadline miss: runtime";
-
-
-int schedfd;
-
-int
-rthandler(void*, char *s)
-{
-	if (s && strncmp(missstr, s, strlen(missstr)) == 0)
-		return 1;
-
-	/* On any other note */
-	if (!besteffort && fprint(schedfd, "remove") < 0)
-		sysfatal("Could not remove task: %r");
-	sysfatal("Removed task");
-	return 1;
-}
-
-static void
-usage(void)
-{
-	fprint(2, "Usage: %s [-d profdev] [-t timedev] [-b] [-v]\n", argv0);
-	exits(nil);
-}
-
-void
-threadmain(int argc, char **argv)
-{
-	ARGBEGIN {
-	case 'T':
-		T = EARGF(usage());
-		break;
-	case 'D':
-		Dl = EARGF(usage());
-		break;
-	case 'C':
-		C = EARGF(usage());
-		break;
-	case 'd':
-		profdev = EARGF(usage());
-		break;
-	case 't':
-		timedev = EARGF(usage());
-		break;
-	case 'b':
-		besteffort++;
-		break;
-	case 'v':
-		verbose++;
-		break;
-	case 'w':
-		newwin++;
-		break;
-	default:
-		usage();
-	}
-	ARGEND;
-
-	if (argc != 0)
-		usage();
-
-	fmtinstall('T', timeconv);
-
-	drawrt();
-}
-
-static void
-mkcol(int i, int c0, int c1, int c2)
-{
-	cols[i][0] = allocimagemix(display, c0, DWhite);
-	cols[i][1] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, c1);
-	cols[i][2] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, c2);
-}
-
-static void
-colinit(void)
-{
-	mediumfont = openfont(display, "/lib/font/bit/lucidasans/unicode.10.font");
-	if(mediumfont == nil)
-		mediumfont = font;
-	tinyfont = openfont(display, "/lib/font/bit/lucidasans/unicode.7.font");
-	if(tinyfont == nil)
-		tinyfont = font;
-	topmargin = mediumfont->height+2;
-	bottommargin = tinyfont->height+2;
-
-	/* Peach */
-	mkcol(0, 0xFFAAAAFF, 0xFFAAAAFF, 0xBB5D5DFF);
-	/* Aqua */
-	mkcol(1, DPalebluegreen, DPalegreygreen, DPurpleblue);
-	/* Yellow */
-	mkcol(2, DPaleyellow, DDarkyellow, DYellowgreen);
-	/* Green */
-	mkcol(3, DPalegreen, DMedgreen, DDarkgreen);
-	/* Blue */
-	mkcol(4, 0x00AAFFFF, 0x00AAFFFF, 0x0088CCFF);
-	/* Grey */
-	cols[5][0] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xEEEEEEFF);
-	cols[5][1] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCFF);
-	cols[5][2] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x888888FF);
-	grey = cols[5][2];
-	red = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xFF0000FF);
-	green = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x00FF00FF);
-	bg = display->white;
-	fg = display->black;
-}
-
-static void
-redraw(int timefd, float scale)
-{
-	int n, i, x;
-	char buf[256];
-	Time ts, now, period, ppp, oldestts;
-	Point p, q;
-	Rectangle r, rtime;
-	Task *t;
-
-#	define time2x(t)	((int)(((t) - oldestts) / ppp))
-
-	if ((n = read(timefd, &now, sizeof(Time))) < 0)
-		sysfatal("redraw: Cannot get time: %r\n");
-	assert(n == sizeof(Time));
-
-	period = (Time)(Onesecond * scale);
-	ppp = (Time)(Onesecond * scale) / Width;	// period per pixel.
-	oldestts = now - period;
-
-	/* white out time */
-	rtime = screen->r;
-	rtime.min.x = rtime.max.x - stringwidth(mediumfont, "0000000.000s");
-	rtime.max.y = rtime.min.y + mediumfont->height;
-	draw(screen, rtime, bg, nil, ZP);
-
-	if (prevts < oldestts){
-		prevts = oldestts;
-		draw(screen, screen->r, bg, nil, ZP);
-		p = screen->r.min;
-		for (n = 0; n != ntasks; n++) {
-			t = &tasks[n];
-			/* p is upper left corner for this task */
-			snprint(buf, sizeof(buf), "%ld ", t->tid);
-			q = string(screen, p, fg, ZP, mediumfont, buf);
-			snprint(buf, sizeof(buf), " %s", t->settings);
-			string(screen, q, fg, ZP, tinyfont, buf);
-			p.y += Height;
-		}
-	}
-	
-	x = time2x(prevts);
-
-	p = screen->r.min;
-	for (n = 0; n != ntasks; n++) {
-		t = &tasks[n];
-
-		/* p is upper left corner for this task */
-
-		/* Move part already drawn */
-		r = Rect(p.x, p.y + topmargin, p.x + x, p.y+Height);
-		draw(screen, r, screen, nil, Pt(p.x + Width - x, p.y + topmargin));
-
-		r.max.x = screen->r.max.x;
-		r.min.x += x;
-		draw(screen, r, bg, nil, ZP);
-
-		line(screen, addpt(p, Pt(x, Height - lineht)), Pt(screen->r.max.x, p.y + Height - lineht),
-			Endsquare, Endsquare, 0, cols[n % Ncolor][1], ZP);
-
-		for (i = 0; i < t->nevents-1; i++)
-			if (prevts < t->events[i + 1].ts)
-				break;
-			
-		if (i > 0) {
-			memmove(t->events, t->events + i,
-				  (t->nevents - i) * sizeof(Schedevent));
-			t->nevents -= i;
-		}
-
-		for (i = 0; i != t->nevents; i++) {
-			Schedevent *e = &t->events[i];
-			int sx, ex, j;
-
-			switch (e->etype) {
-			case SRelease:
-
-				if (e->ts > prevts && e->ts <= now) {
-					sx = time2x(e->ts);
-					line(screen, addpt(p, Pt(sx, topmargin)), addpt(p, Pt(sx, Height - bottommargin)), 
-						Endarrow, Endsquare, 1, fg, ZP);
-				}
-				break;
-			case SDeadline:
-				if (e->ts > prevts && e->ts <= now) {
-					sx = time2x(e->ts);
-					line(screen, addpt(p, Pt(sx, topmargin)), addpt(p, Pt(sx, Height - bottommargin)), 
-						Endsquare, Endarrow, 1, fg, ZP);
-				}
-				break;
-
-			case SYield:
-				if (e->ts > prevts && e->ts <= now) {
-					sx = time2x(e->ts);
-					line(screen, addpt(p, Pt(sx, topmargin)), addpt(p, Pt(sx, Height - bottommargin)), 
-						Endsquare, Endarrow, 0, green, ZP);
-				}
-				break;
-
-			case SSlice:
-				if (e->ts > prevts && e->ts <= now) {
-					sx = time2x(e->ts);
-					line(screen, addpt(p, Pt(sx, topmargin)), addpt(p, Pt(sx, Height - bottommargin)), 
-						Endsquare, Endarrow, 0, red, ZP);
-				}
-				break;
-
-			case SBlock:
-			case SExpel:
-				break;
-
-			case SPreempt:
-				for (j = i + 1; j < t->nevents; j++) {
-					if (t->events[j].etype == SRun)
-						break;
-				}
-				if (j >= t->nevents)
-					break;
-				if (t->events[j].ts < prevts)
-					break;
-
-				sx = time2x(e->ts);
-				ex = time2x(t->events[j].ts);
-
-				r = Rect(sx, Height - lineht - 8, ex, Height - lineht);
-				r = rectaddpt(r, p);
-
-				draw(screen, r, cols[n % Ncolor][1], nil, ZP);
-				break;
-
-			case SRun:
-			case SResume:
-
-				for (j = i + 1; j < t->nevents; j++) {
-					if (t->events[j].etype == SBlock
-					  || t->events[j].etype == SPreempt
-					  || t->events[j].etype == SYield
-					  || t->events[j].etype == SSlice)
-						break;
-				}
-
-				if (j >= t->nevents)
-					break;
-				if (t->events[j].ts < prevts)
-					break;
-
-				sx = time2x(e->ts);
-				ex = time2x(t->events[j].ts);
-
-				r = Rect(sx, topmargin + 8, ex, Height - lineht);
-				r = rectaddpt(r, p);
-
-				draw(screen, r, cols[n % Ncolor][1], nil, ZP);
-				break;
-			}
-		}
-		p.y += Height;
-	}
-
-	ts = roundup(prevts, period / 10);
-	x = time2x(ts);
-
-	while (x < Dx(screen->r)) {
-
-		p = screen->r.min;
-		for (n = 0; n < ntasks; n++) {
-			int height, width;
-
-			/* p is upper left corner for this task */
-
-			if ((ts % (period / 2)) == 0) {
-				height = Height / 2;
-				width = 1;
-			}
-			else {
-				height = 3 * Height / 4;
-				width = 0;
-			}
-
-			line(screen, addpt(p, Pt(x, height)), addpt(p, Pt(x, Height - lineht)),
-				Endsquare, Endsquare, width, cols[n % Ncolor][2], ZP);
-
-			p.y += Height;
-		}
-
-		if ((ts % (period / 2)) == 0) {
-			snprint(buf, sizeof(buf), "%T", ts);
-			string(screen, addpt(p, Pt(x - stringwidth(tinyfont, buf)/2, - tinyfont->height - 1)), 
-				fg, ZP, tinyfont, buf);
-		}
-
-		ts += period / 10;
-		x += Width / 10;
-	}
-
-	snprint(buf, sizeof(buf), "%T ", now);
-	string(screen, Pt(screen->r.max.x - stringwidth(mediumfont, buf), screen->r.min.y), fg, ZP, mediumfont, buf);
-	
-	flushimage(display, 1);
-	prevts = now;
-}
-
-void
-drawrt(void)
-{
-	char *wsys, line[256];
-	int wfd, wctlfd, timefd, logfd, fd;
-	Mousectl *mousectl;
-	Keyboardctl *keyboardctl;
-	int paused;
-	float scale;
-	Rune r;
-	int i, m, n;
-	Task *t;
-
-	event = malloc(sizeof(Schedevent));
-	assert(event);
-
-	if ((logfd = open(profdev, OREAD)) < 0)
-		sysfatal("%s: Cannot open %s: %r\n", argv0, profdev);
-
-	if ((timefd = open(timedev, OREAD)) < 0)
-		sysfatal("%s: Cannot open %s: %r\n", argv0, timedev);
-
-	if (newwin){
-		if ((wsys = getenv("wsys")) == nil)
-			sysfatal("drawrt: Cannot find windowing system: %r\n");
-	
-		if ((wfd = open(wsys, ORDWR)) < 0)
-			sysfatal("drawrt: Cannot open windowing system: %r\n");
-	
-		snprint(line, sizeof(line), "new -pid %d -dx %d -dy %d", getpid(), Width + 20, Height + 5);
-		line[sizeof(line) - 1] = '\0';
-		rfork(RFNAMEG);
-	
-		if (mount(wfd, -1, "/mnt/wsys", MREPL, line) < 0) 
-			sysfatal("drawrt: Cannot mount %s under /mnt/wsys: %r\n", line);
-	
-		if (bind("/mnt/wsys", "/dev", MBEFORE) < 0) 
-			sysfatal("drawrt: Cannot bind /mnt/wsys in /dev: %r\n");
-	
-	}
-	if ((wctlfd = open("/dev/wctl", OWRITE)) < 0)
-		sysfatal("drawrt: Cannot open /dev/wctl: %r\n");
-	if (initdraw(nil, nil, "rtprof") < 0)
-		sysfatal("drawrt: initdraw failure: %r\n");
-
-	Width = Dx(screen->r);
-	Height = Dy(screen->r);
-
-	if ((mousectl = initmouse(nil, screen)) == nil)
-		sysfatal("drawrt: cannot initialize mouse: %r\n");
-
-	if ((keyboardctl = initkeyboard(nil)) == nil)
-		sysfatal("drawrt: cannot initialize keyboard: %r\n");
-
-	colinit();
-
-	SET(schedfd);
-	if (!besteffort){
-		schedfd = schedparse(T, Dl, C);
- 		atnotify(rthandler, 1);
-	}
-
-	paused = 0;
-	scale = 1.;
-	while (1) {
-		Alt a[] = {
-			{ mousectl->c,			nil,		CHANRCV		},
-			{ mousectl->resizec,	nil,		CHANRCV		},
-			{ keyboardctl->c,		&r,		CHANRCV		},
-			{ nil,					nil,		CHANNOBLK	},
-		};
-
-		switch (alt(a)) {
-		case 0:
-			continue;
-
-		case 1:
-			if (getwindow(display, Refnone) < 0)
-				sysfatal("drawrt: Cannot re-attach window\n");
-			if (newwin){
-				if (Dx(screen->r) != Width || Dy(screen->r) != (ntasks * Height)){
-					fprint(2, "resize: x: have %d, need %d; y: have %d, need %d\n",
-						Dx(screen->r), Width + 8, Dy(screen->r), (ntasks * Height) + 8);
-					fprint(wctlfd, "resize -dx %d -dy %d\n", Width + 8, (ntasks * Height) + 8);
-				}
-			}else{
-				Width = Dx(screen->r);
-				Height = Dy(screen->r)/ntasks;
-			}
-			break;
-
-		case 2:
-
-			switch (r) {
-			case 'p':
-				if (!paused)
-					paused = 1;
-				else
-					paused = 0;
-				prevts = 0;
-				break;
-
-			case '+':
-				scale /= 2.;
-				prevts = 0;
-				break;
-
-			case '-':
-				scale *= 2.;
-				prevts = 0;
-				break;
-
-			case 'q':
-				rthandler(nil, nil);
-				threadexitsall(nil);
-
-			default:
-				break;
-			}
-			break;
-			
-		case 3:
-			while((n = read(logfd, event, sizeof(Schedevent))) > 0){
-
-				assert(n == sizeof(Schedevent));
-
-				if (verbose)
-					print("%ud %T %s\n", event->tid, event->ts, schedstatename[event->etype]);
-				for (i = 0; i < ntasks; i++)
-					if (tasks[i].tid == event->tid)
-						break;
-
-				if (i == ntasks) {
-					tasks = realloc(tasks, (ntasks + 1) * sizeof(Task));
-					assert(tasks);
-
-					t = &tasks[ntasks++];
-					t->events = nil;
-					t->settings = nil;
-					t->nevents = 0;
-					t->events = nil;
-					t->tid = event->tid;
-					snprint(line, sizeof line, "%s/%ud", taskdir, event->tid);
-					if ((fd = open(line, OREAD)) < 0)
-						goto expel;
-					m = read(fd, line, sizeof line - 1);
-					close(fd);
-					if (m < 0)
-						goto expel;
-					line[m] = 0;
-					if (m && line[--m] == '\n')
-						line[m] = 0;
-					t->settings = strdup(line);
-					prevts = 0;
-					if (newwin){
-						fprint(wctlfd, "resize -dx %d -dy %d\n",
-							Width + 20, (ntasks * Height) + 5);
-					}else
-						Height = Dy(screen->r)/ntasks;
-				} else
-					t = &tasks[i];
-				
-				if (event->etype == SExpel){
-		expel:
-					free(t->events);
-					free(t->settings);
-					ntasks--;
-					memmove(t, t+1, sizeof(Task)*(ntasks-i));
-					if (newwin)
-						fprint(wctlfd, "resize -dx %d -dy %d\n",
-							Width + 20, (ntasks * Height) + 5);
-					else
-						Height = Dy(screen->r)/ntasks;
-					prevts = 0;
-				}else{
-					t->events = realloc(t->events, (t->nevents+1)*sizeof(Schedevent));
-					assert(t->events);
-					memcpy(&t->events[t->nevents], event, sizeof(Schedevent));
-					t->nevents++;
-				}
-			}
-			if (!paused)
-				redraw(timefd, scale);
-		}
-		if (besteffort)
-			sleep(100);
-		else if (fprint(schedfd, "yield") < 0)
-			sysfatal("yield: %r");
-	}
-}
-
-int
-schedparse(char *period, char *deadline, char *slice)
-{
-	int schedfd;
-
-	if ((schedfd = open(clonedev, ORDWR)) < 0) 
-		sysfatal("%s: %r", clonedev);
-	
-	fprint(2, "T=%s D=%s C=%s procs=%d admit\n", period, deadline, slice, getpid());
-	if (fprint(schedfd, "T=%s D=%s C=%s procs=%d admit", period, deadline, slice, getpid()) < 0)
-		sysfatal("%s: %r", clonedev);
-
-	return schedfd;
-}

+ 0 - 101
sys/src/cmd/rtstats/time.c

@@ -1,101 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include "realtime.h"
-#include "time.h"
-
-Ticks	fasthz;
-
-static uvlong
-uvmuldiv(uvlong x, ulong num, ulong den)
-{
-	/* multiply, then divide, avoiding overflow */
-	uvlong hi;
-
-	hi = (x & 0xffffffff00000000LL) >> 32;
-	x &= 0xffffffffLL;
-	hi *= num;
-	return (x*num + (hi%den << 32)) / den + (hi/den << 32);
-}
-
-Time
-ticks2time(Ticks ticks)
-{
-	assert(ticks >= 0);
-	return uvmuldiv(ticks, Onesecond, fasthz);
-}
-
-Ticks
-time2ticks(Time time)
-{
-	assert(time >= 0);
-	return uvmuldiv(time, fasthz, Onesecond);
-}
-
-int
-timeconv(Fmt *f)
-{
-	char buf[128], *sign;
-	Time t;
-	Ticks ticks;
-
-	buf[0] = 0;
-	switch(f->r) {
-	case 'U':
-		ticks = va_arg(f->args, Ticks);
-		t = ticks2time(ticks);
-		break;
-	case 'T':		// Time in nanoseconds
-		t = va_arg(f->args, Time);
-		break;
-	default:
-		return fmtstrcpy(f, "(timeconv)");
-	}
-	if (t < 0) {
-		sign = "-";
-		t = -t;
-	}
-	else
-		sign = "";
-	if (t > Onesecond)
-		sprint(buf, "%s%d.%.3ds", sign, (int)(t / Onesecond), (int)(t % Onesecond)/1000000);
-	else if (t > Onemillisecond)
-		sprint(buf, "%s%d.%.3dms", sign, (int)(t / Onemillisecond), (int)(t % Onemillisecond)/1000);
-	else if (t > Onemicrosecond)
-		sprint(buf, "%s%d.%.3dµs", sign, (int)(t / Onemicrosecond), (int)(t % Onemicrosecond));
-	else
-		sprint(buf, "%s%dns", sign, (int)t);
-	return fmtstrcpy(f, buf);
-}
-
-char *
-parsetime(Time *rt, char *s)
-{
-	uvlong ticks;
-	ulong l;
-	char *e, *p;
-	static int p10[] = {100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};
-
-	if (s == nil)
-		return("missing value");
-	ticks=strtoul(s, &e, 10);
-	if (*e == '.'){
-		p = e+1;
-		l = strtoul(p, &e, 10);
-		if(e-p > nelem(p10))
-			return "too many digits after decimal point";
-		if(e-p == 0)
-			return "ill-formed number";
-		l *= p10[e-p-1];
-	}else
-		l = 0;
-	if (*e == '\0' || strcmp(e, "s") == 0){
-		ticks = 1000000000 * ticks + l;
-	}else if (strcmp(e, "ms") == 0){
-		ticks = 1000000 * ticks + l/1000;
-	}else if (strcmp(e, "µs") == 0 || strcmp(e, "us") == 0){
-		ticks = 1000 * ticks + l/1000000;
-	}else if (strcmp(e, "ns") != 0)
-		return "unrecognized unit";
-	*rt = ticks;
-	return nil;
-}

+ 0 - 9
sys/src/cmd/rtstats/time.h

@@ -1,9 +0,0 @@
-
-#pragma	varargck	type	"T"		vlong
-
-extern	Ticks	fasthz;
-
-int		timeconv(Fmt*);
-Time		ticks2time(Ticks);
-Ticks	time2ticks(Time);
-char *	parsetime(Time *rt, char *s);