blktrace version v2.0.0
note: in blkparse output, the m in the sixth column indicate the line is scheduler information.
On Ubuntu 16.04 ext4 I can see the IO Scheduler message, blktrace -d /dev/sda -o - | blkparse -i -
8,0 3 1 0.000000000 24714 A WS 76519424 + 2048 <- (8,1) 76517376
8,0 3 2 0.000000861 24714 Q WS 76519424 + 2048 [TaskSchedulerFo]
8,0 3 3 0.000005084 24714 X WS 76519424 / 76520768 [TaskSchedulerFo]
8,0 3 4 0.000008962 24714 G WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 5 0.000009379 24714 P N [TaskSchedulerFo]
8,0 3 6 0.000012021 24714 G WS 76520768 + 704 [TaskSchedulerFo]
8,0 3 7 0.000012622 24714 I WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 0 0.000015209 0 m N cfq24714SN /user.slice insert_request
8,0 3 0 0.000016074 0 m N cfq24714SN /user.slice add_to_rr
8,0 3 0 0.000017548 0 m N cfq24714SN /user.slice preempt
8,0 3 0 0.000018184 0 m N cfq25055SN /user.slice slice expired t=1
8,0 3 0 0.000018982 0 m N cfq25055SN /user.slice resid=-2643710186
8,0 3 0 0.000020125 0 m N /user.slice served: vt=247310740068 min_vt=247310580285
8,0 3 0 0.000021297 0 m N cfq25055SN /user.slice sl_used=33325195 disp=13 charge=13 iops=1 sect=1088
8,0 3 0 0.000021822 0 m N cfq25055SN /user.slice del_from_rr
8,0 3 0 0.000023767 0 m N cfq workload slice:100000000
8,0 3 0 0.000024496 0 m N cfq24714SN /user.slice set_active wl_class:0 wl_type:1
8,0 3 0 0.000025395 0 m N cfq24714SN /user.slice dispatch_insert
8,0 3 0 0.000026232 0 m N cfq24714SN /user.slice dispatched a request
8,0 3 0 0.000026818 0 m N cfq24714SN /user.slice activate rq, drv=1
8,0 3 8 0.000027030 24714 D WS 76519424 + 1344 [TaskSchedulerFo]
8,0 3 9 0.000037848 24714 U N [TaskSchedulerFo] 1
8,0 3 10 0.000038118 24714 P N [TaskSchedulerFo]
8,0 3 11 0.000048153 24714 A WS 76521472 + 264 <- (8,1) 76519424
8,0 3 12 0.000048340 24714 Q WS 76521472 + 264 [TaskSchedulerFo]
8,0 3 13 0.000049444 24714 M WS 76521472 + 264 [TaskSchedulerFo]
8,0 3 14 0.000050486 24714 I WS 76520768 + 968 [TaskSchedulerFo]
8,0 3 0 0.000051332 0 m N cfq24714SN /user.slice insert_request
8,0 3 15 0.000051755 24714 U N [TaskSchedulerFo] 1
8,0 3 0 0.000052418 0 m N cfq24714SN /user.slice dispatch_insert
8,0 3 0 0.000053068 0 m N cfq24714SN /user.slice dispatched a request
8,0 3 0 0.000053604 0 m N cfq24714SN /user.slice activate rq, drv=2
8,0 3 16 0.000053721 24714 D WS 76520768 + 968 [TaskSchedulerFo]
8,0 2 1 0.001844211 0 C WS 76519424 + 1344 [0]
8,0 2 0 0.001849143 0 m N cfq24714SN /user.slice complete rqnoi
on CentOS 7.4 xfs,I can not see the IO Scheduler message, blktrace -d /dev/sdb -o - | blkparse -i -
8,16 25 1 0.000000000 11966 Q R 73400472 + 128 [fio]
8,16 25 2 0.000006237 11966 G R 73400472 + 128 [fio]
8,16 25 3 0.000007806 11966 P N [fio]
8,16 25 4 0.000010836 11966 I R 73400472 + 128 [fio]
8,16 25 5 0.000011878 11966 U N [fio] 1
8,16 25 6 0.000013900 11966 D R 73400472 + 128 [fio]
8,16 10 1 0.008284979 0 C R 73400472 + 128 [0]
8,16 10 2 0.008343574 11966 Q R 73400600 + 128 [fio]
8,16 10 3 0.008345976 11966 G R 73400600 + 128 [fio]
8,16 10 4 0.008346908 11966 P N [fio]
8,16 10 5 0.008348926 11966 I R 73400600 + 128 [fio]
8,16 10 6 0.008349651 11966 U N [fio] 1
8,16 10 7 0.008350694 11966 D R 73400600 + 128 [fio]
8,16 8 1 0.008771249 0 C R 73400600 + 128 [0]
While there are program version differences between the setups (in CentOS 7 blktrace is version 1.0.5 and the kernel is based off 3.10 whereas in Ubuntu 16.04 blktrace is version 1.1.0 and the kernel may be between 4.4 - 4.10) the real point may be down to what was asked (but unfortunately went unanswered) in one of the comments:
what [I/O] scheduler was in use
If we look at one of your m lines:
8,0 3 0 0.000015209 0 m N cfq24714SN /user.slice insert_request
we can see that it is a textual message (hence the m) and that it likely came from the CFQ I/O scheduler (hence the cfq prefix on the message itself). If the I/O scheduler being used for the /dev/sdb device on the CentOS 7 setup was not CFQ (e.g. because the noop I/O scheduler was being used) then we cannot expect similar messages to be present.
So bringing this back to the title of the question:
blkparse how to show IO Scheduler message
If an I/O scheduler wants to it can send free form blktrace text (e.g. see block/cfq-iosched.c which has calls to blk_add_trace_msg() in it) but not all I/O schedulers do (e.g. see block/noop-iosched.c which doesn't even include the linux/blktrace_api.h header). By default blkparse will show all messages present unless you use the -M option to suppress them.
Related
I have a function ℚ -> ℚ -> Bool taking a Cartesian coordinate, where true stands for black and false for white. Is there any existing library that I can use to "rasterize" it into a bitmap image?
The PBM file format is a pretty simple text-based image file format. See https://en.wikipedia.org/wiki/Netpbm for a description. It's easy to write code to produce PBM files.
For the function λ x y → x ≤ᵇ y, the below code outputs the following PBM file contents:
P1
20 10
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
The lines mean the following:
P1 is a magic number that identifies the file format.
20 10 are the width and height of the image.
Each of the remaining lines represents one line of the image. 1 represents a black pixel and 0 a white pixel.
Put the above contents in a .pbm file (say, test.pbm) and you have something that you can open in image processing tools that support PBM files.
The makePBM function takes the width and height of the image to be produced, the x and y starting points in ℚ, the step to make in ℚ for each pixel in the x and y direction, and the ℚ → ℚ → Bool function to be evaluated.
--guardedness is only required, because I use IO for demonstration purposes.
{-# OPTIONS --guardedness #-}
module Raster where
open import Data.Bool using (Bool ; if_then_else_)
open import Data.Nat using (ℕ ; zero ; suc)
open import Data.Nat.Show using (show)
open import Data.Rational using (ℚ ; 0ℚ ; 1ℚ ; _+_ ; _≤ᵇ_)
open import Data.String using (String ; _++_)
open import IO using (Main ; run ; putStrLn)
-- width height offset-x offset-y step-x step-y function
makePBM : (w h : ℕ) → (ox oy sx sy : ℚ) → (ℚ → ℚ → Bool) → String
makePBM w h ox oy sx sy f = header ++ bitmap h oy
where
header : String
header = "P1\n" ++ show w ++ " " ++ show h ++ "\n"
row : (n : ℕ) → (x y : ℚ) → String
row zero x y = "\n"
row (suc n) x y = pixel ++ " " ++ row n (x + sx) y
where pixel = if f x y then "1" else "0"
bitmap : (n : ℕ) → (y : ℚ) → String
bitmap zero y = ""
bitmap (suc n) y = row w ox y ++ bitmap n (y + sy)
testPBM : String
testPBM = makePBM 20 10 0ℚ 0ℚ 1ℚ 1ℚ (λ x y → x ≤ᵇ y)
main : Main
main = run (putStrLn testPBM)
I'd be very surprised if there were. I'm not aware of any work on image manipulations in Agda.
Having said that, it should be relatively easy to do.
Create a m x n matrix of type Vector (Vector ℕ m) n from Data.Vec.Functional containing (i,j) at the ith row and jth column.
Map each (i,j) to the desired range of coordinates in the image.
Map the function f : ℚ -> ℚ -> Bool over each the entire matrix.
I have an expression that actually can be expressed in simple form by collecting the specific terms. I have problem in Maxima to substitute or simplify the expression to the known terms.
(%i1) expr:(16*h^2*v_0^2+(38*h*u_0-38*h*u_1)*v_0+25*u_1^2-50*u_0*u_1+25*u_0^2)/3;
2 2 2 2
16 h v_0 + (38 h u_0 - 38 h u_1) v_0 + 25 u_1 - 50 u_0 u_1 + 25 u_0
(%o1) -----------------------------------------------------------------------
3
(%i2) eq1:a1=-h*v_0+2*u_1-2*u_0;
eq2:a2=-2*(h*v_0-u_1+u_0);
(%o2) a1 = (- h v_0) + 2 u_1 - 2 u_0
(%i3)
(%o3) a2 = - 2 (h v_0 - u_1 + u_0)
(%i4) subst([eq1,eq2],expr);
2 2 2 2
16 h v_0 + (38 h u_0 - 38 h u_1) v_0 + 25 u_1 - 50 u_0 u_1 + 25 u_0
(%o4) -----------------------------------------------------------------------
3
What I want is something like this
expr=c1*(a1)^q1 + c2*(a2)^q2
where c1,c2,q1,q2 are the constant that would generated by simplifying expr using known term a1,a2. How to do that? Is there any specific syntax?
I have this data frame
AutoStat_1 AutoStat_2 Mode_1 Mode_2 Setpoint_1 Setpoint_2
0 -> 0 0 1 1 23 24
1 -> 0 1 1 0 23 27
2 -> 1 1 3 0 26 27
3 -> 1 0 3 1 26 24
4 -> 0 0 1 2 24 24
5 -> 0 0 1 2 24 24
6 -> 2 3 0 4 24 26
7 -> 2 3 0 4 25 26
The requirement is that if AutoStat_i is not 0 then Mode_i and Setpoint_i will be the value of the above (in-front) of which AutoStat_i is 0
The result should be (notice the column Setpoint_i and Mode_i are different than above)
AutoStat_1 AutoStat_2 Mode_1 Mode_2 Setpoint_1 Setpoint_2
0 -> 0 0 1 1 23 24
1 -> 0 1 1 1 23 24
2 -> 1 1 1 1 23 24
3 -> 1 0 1 1 23 24
4 -> 0 0 1 2 24 24
5 -> 0 0 1 2 24 24
6 -> 2 3 1 2 24 24
7 -> 2 3 1 2 24 24
What've I tried:
My idea is for each set i of (AutoStat_i, Mode_i, Setpoint_i), scan each row if AutoStat_i is <> 0 then set the other values to NaN, after that I will just do the fillMissing with Direction.Forward. Below is the impementation
let calculateNonSFi (df:Frame<_,string>) idx =
let autoStatusName = sprintf "AutoStat_%d" idx
let setpointName = sprintf "Setpoint_%d" idx
let modeName = sprintf "Mode_%d" idx
let setMissingOnMode (s:ObjectSeries<string>) =
let s2 = s.As<float>()
if s2.[autoStatusName] <> 0. then
Series.replaceArray [|setpointName;modeName|] Double.NaN s2
else
s2
df.Rows
|> Series.mapValues setMissingOnMode
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
|> Frame.fillMissing Direction.Backward
// for each set i do the folding
[0..150]
|> List.fold calculateNonSFi df
It gave me the expected results, however, for 150sets of 8000rows, it took more than 30 minutes to complete. I kinda see where it's wrong as for every set it acts on the whole dataset but I cannot think of a better way.
The logic is quite simple. I believe there should be a better way, do advice, thanks.
UPDATE
Here is the code for reproduction
open Deedle
open System
let df =
[
{| AutoStat_1=0;Setpoint_1=23;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=0;Setpoint_1=23;Mode_1=1;AutoStat_2=1;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=1;Setpoint_1=23;Mode_1=1;AutoStat_2=1;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=1;Setpoint_1=23;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=1|}
{| AutoStat_1=0;Setpoint_1=24;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=0;Setpoint_1=24;Mode_1=1;AutoStat_2=0;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=2;Setpoint_1=24;Mode_1=1;AutoStat_2=3;Setpoint_2=24;Mode_2=2|}
{| AutoStat_1=2;Setpoint_1=24;Mode_1=1;AutoStat_2=3;Setpoint_2=24;Mode_2=2|}
] |> Frame.ofRecords
df.Print()
let calculateNonSFi (df:Frame<_,string>) idx =
let autoStatusName = sprintf "AutoStat_%d" idx
let setpointName = sprintf "Setpoint_%d" idx
let modeName = sprintf "Mode_%d" idx
let setMissingOnMode (s:ObjectSeries<string>) =
let s2 = s.As<float>()
if s2.[autoStatusName] <> 0. then
Series.replaceArray [|setpointName;modeName|] Double.NaN s2
else
s2
df.Rows
|> Series.mapValues setMissingOnMode
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
let df1 =
[1..2]
|> List.fold calculateNonSFi df
df1.Print()
Advice/Answer from Tomas
df
|> Frame.mapRows (fun _ o ->
[ for i in 0 .. 150 do
let au = o.GetAs<float>("AutoStat_" + string i)
yield "AutoStat_" + string i, au
yield "Mode_" + string i, if au <> 0. then nan else o.GetAs("Mode_" + string i)
yield "Setpoint_" + string i, if au <> 0. then nan else o.GetAs("Setpoint_" + string i) ]
|> series )
|> Frame.ofRows
|> Frame.fillMissing Direction.Forward
which yields correct result but in different column order hence my mistake in the earlier edit
AutoStat_1 Mode_1 Setpoint_1 AutoStat_2 Mode_2 Setpoint_2
0 -> 0 1 23 0 1 24
1 -> 0 1 23 1 1 24
2 -> 1 1 23 1 1 24
3 -> 1 1 23 0 1 24
4 -> 0 1 24 0 2 24
5 -> 0 1 24 0 2 24
6 -> 2 1 24 3 2 24
7 -> 2 1 24 3 2 24
First of all, I think your strategy of setting Mode_i and Setpoint_i to NA when AutoStat_i is not 0 and then filling the missing values is a nice approach.
You can certainly make it a bit faster by moving the fillMissing call outside of the calculateNonSFi function - the fillMissing operation will run on the whole frame, so you need to run this once at the end.
The second thing would be to find a way of setting the NA values that only iterates over the frame once. One option (I have not tested this) would be to use Frame.mapRows and, inside the function, iterate over all the columns (rather than iterating over all the columns and calling mapRows repeatedly). Something like:
df
|> Frame.mapRows (fun _ o ->
[ for i in 0 .. 150 do
let au = o.GetAs<float>("AutoStat_" + string i)
yield "AutoStat_" + string i, au
yield "Mode_" + string i, if au = 0. then nan else o.GetAs("Mode_" + string i)
yield "Setpoint_" + string i, if au = 0. then nan else o.GetAs("Setpoint_" + string i) ]
|> series )
|> Frame.ofRows
GNU DC displays the stack vertically, (f displays the stack)
1 2 3 4
f # to display the stack
4
3
2
1
Is there a way to change this to be more like FORTH? While GNU FORTH displays the stack horizontally, (.s displays the stack)
1 2 3 4 ok
.s <4> 1 2 3 4 ok
You can create custom function in ~/.dcrc which is read each time dc start.
cat ~/.dcrc
[
# if the stack is empty
[ 2 + [stack empty] p 0 :- Q ]s-
z d 0 =- 0 :-
# keep the stack in indexed array -
[ z :- z 0 <- ]s-
l-x
# restore the stack
[ 0 ;- 1 + d ;- ;- r d ;- 1 + r :- 0 ;- d 1 + ;- r !<- ]s-
1 0 ;- 1 + :-
l-x
# displays the stack horizontally
[ 0 ;- d 1 + d ;- ;- n [ ] n d d ;- 1 + r :- ;- !>- ]s-
1 0 ;- 1 + :- l-x [ ok] p 0 :-
]s-
You call it this way :
echo '7 16 8 9' | dc -f - -e 'l-x f'
and you get :
7 16 8 9 ok
9
8
16
7
You cannot use register -
I'm trying to compare two ways of printing a multiplication table, and even though they print identical strings when i printf "%s" mulTable n and printf "%s" loopMulTable n, they dont seem to be the same thing when comparing them, as it prints false for every comparison in the last function. Can anyone explain to me why?
let a = " 1 2 3 4 5 6 7 8 9 10
1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
6 6 12 18 24 30 36 42 48 54 60
7 7 14 21 28 35 42 49 56 63 70
8 8 16 24 32 40 48 56 64 72 80
9 9 18 27 36 45 54 63 72 81 90
10 10 20 30 40 50 60 70 80 90 100"
let mulTable n =
a.[0..(n*54)+51]
let loopMulTable n =
let mutable returnString = ""
returnString <- returnString + (sprintf " ")
for i in 1..10 do
returnString <- returnString + (sprintf "%5d" i)
for x in 1..n do
returnString <- returnString + (sprintf "\n")
returnString <- returnString + (sprintf "%2d" x)
for y in 1..10 do
returnString <- returnString + (sprintf "%5d" (x*y))
returnString
let o = "n:"
let u = "boolean value:"
let chooseN n =
printfn "%5s %19s" o u
for n in 1..n do
printfn "%4d %15b" n ((loopMulTable n)=(mulTable n))
chooseN 5
Might i add that i am a beginner in programming and especially in F#, so there might be other flaws though they're not the problem that i'm looking to solve.
Thanks!
The test for equality is most likely failing because this line is appending a newline rather than a carriage-return-newline combination.
returnString <- returnString + (sprintf "\n")
If you are on a Windows machine, the line breaks in your source code will most likely include the carriage return character. Change it to the following and it should compare just fine:
returnString <- returnString + (sprintf "\r\n")