File: gen2.awk

package info (click to toggle)
sockperf 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,912 kB
  • sloc: cpp: 8,092; perl: 7,225; sh: 3,254; makefile: 114; awk: 93
file content (54 lines) | stat: -rwxr-xr-x 1,856 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/awk -f
#
# this awk script generates playback files to be played with ./sockperf --playback command
# the input for this script is file with lines of the format:
# startTime; duration; startPPS; endPPS; msgSize
# example for such a file is: 
#            1 2  100 100 12
#            3 1  100 10  12
#            4 10 10  100 12
#
BEGIN {
	print "# ==== playback file for sockperf - generated by gen2.awk ===="
}

# file start => echo all orig lines as block of comments
FNR == 1 && FILENAME != "-" {
	print "#---> echoing the content of the given input file: " FILENAME
	system("sed 's/^/#> /' " FILENAME)
	print "#<--- end of input file: " FILENAME
}

{print "#> " $0}   # echo orig line as comment line
/^[ \t]*$/ {next}  # skip empty line
/^[ \t]*#/ {next}  # skip comment line
NF < 5 {error = 1; exit 1} # too few fields

# this will be executed for any input line
{
	runtime = 0; startTime = $1; duration = $2; startPPS=$3; endPPS=$4; msgSize=$5
	if (startTime < t) { error = 1; exit 2} # file is un-ordered
	if (duration <= 0 || startPPS <= 0 || endPPS <= 0 || msgSize < 14 || msgSize > 65000) { error = 1; exit 3}
	
	ppsGradient = (endPPS - startPPS) / duration
	#pps = startPPS
	#runtime += 1/pps
	
	printf ("#startTime=%f; duration=%f; startPPS=%f; endPPS=%f; msgSize=%d; ppsGradient=%f\n", startTime, duration, startPPS, endPPS, msgSize, ppsGradient)
	print("#txTime, msgSize")      # print header
	while (runtime <= duration) {
		t = startTime + runtime
		printf("%.9lf, %d\n", t, msgSize) # actual printing of the record #TODO: 12 digits!
		pps = startPPS + ppsGradient * runtime
		runtime += 1/pps
		counter++
	} 
}

END {
	if (!error)
		printf "# ==== file generation completed successfuly with %d records ====\n", counter
	else
		printf " ====> error has occured during file generation [file=%s : line=%d] <====\n", FILENAME, FNR
}