calculate the amount of bytes written by consecutives write() calls in a second
Idk exactly but i think time.h's time() returns a long representing milli secs from 1/1/1970 (like its java System class equ) you can simply store it in a var and then substract them from each other after invoking your write() calls
Well you edited your question to do this each second. You can do this in a new thread and sleep()
To do so i believe i'd need to add a pthread_lock on the variable of the total bytes written, and considering the sleep not being precise, the lock adding delay for the next writing cycle, i think the calculations would result very wrong. Maybe not all the calculations but probably more than i'd love
Writing speeds of what? What do you want to measure? Could you please elaborate?
1. Bytes written in a system call to the write(fd,buf,count) function 2. Bytes per second 3. It is in C, linux, nothing else
Use std::chrono to measure time of writing 1MB of bytes
Stıll depends on what kınd of Kernel you have, and what will be jitters at that time. Because, if you don't have real-time patched Kernel on the system. you cannot know that how much you need for writing (you have to collect a few measurement and divide by number of trials) even though some jitters will affect your measurement like SMIs, timers etc.
You shouldn't guess or ensure how many bytes you can write per second because of these problems.
Bytes per second👆
Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux
I was saying that it depends on many different things. Measurement will be valid only on your machine, and also maybe how many bytes you will write etc, caching, page faults, timers etc. Many parameter can affect on your result.
I don't need to use the measurements out of my code, so the results can be considered valid(?) The bytes i write are returned by write(), so it is a precise measure
How do you know that when you call write() function, other threads or interrupts on the kernel whether block or not your write() function?
I've tried the code, but i've got to compare it to more precise timing options
More precise like? It’s very precise to function call within start/stop; you just need to fix buffer to bytes.. little code
Hmmm in that case -1 is returned, which is the case in which i have to re-write and don't consider the write output for measurements, making them temporarily non-usable
Do you have information about Linux Kernel or Operating systems at all?
You can google it too! Here is sample. —> https://mobile.happycodings.com/c//beginners-lab-assignments/code47.html
I think that your code makes good measurements only in CPUs with stable and non-adaptable clocks , which isn't always true
Kind of, why ask?
What I was trying to say, you cannot know precisely in user-space how many bytes you can write per second, or you cannot expect to see the same values for each second.
I absolutely do not expect that always the same values will present. I have not gone into precise details in order to not expand on other topics, but the file descriptor is actually a socket. I am making uploads with that write function
Обсуждают сегодня