ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
Can anyone help me to solve this problem?
I wanna convert a timer file from a window program(VC++6.0) into Linux.
There are "GetTickCount(),QueryPerformanceFrequency(),QueryPerformanceCounter()".
GetTickCount() return number of milliseconds that have elapsed since the system was started.
QueryPerformanceFrequency() retrieves the frequency of the high-resolution performance counter.
QueryPerformanceCounter() retrieves the current value of the high-resolution performance counter.
How can I create three functions to replace them ?
I had already change the GetTickCount() but I don't know is it correct or not.
#include <sys/time.h>
unsigned int Timer::GetTickCount()
{
timeval t;
if (gettimeofday(&t,NULL)==0)
return t.tv_usec;
}
I saw the "sys/time.h","sys/times.h","time.h","linux/times.h","linux/time.h" and "linux/timer.h" but I still don't have any idea for replacing QueryPerformanceFrequency() and QueryPerformanceCounter().
I would be gratefully if you can help me to solve the problem
Thanks
Thank you very much "Marius2 " for your help and reply.
But, I am not really understand your program.
the variable "gtod_start_time.tv_usec" is come from where?
is it "gettimeofday(>od_start_time,0);" called in other place?
In fact, what is the different between gtod_start_time and gtod_now_time?
GetTickCount return millisecond (in window original function)but tv_usec return microsecond(in linux time.h). micro=1/1000milli. is it "*1000" not "/1000"?
QueryPerformanceFrequency() and QueryPerformanceCounter() are really difficult to migrate to Linux.
Do anyone know any functions or methods that can get the CPU counter values in Linux?
thx
Originally posted by chanwing Thank you very much "Marius2 " for your help and reply.
But, I am not really understand your program.
the variable "gtod_start_time.tv_usec" is come from where?
is it "gettimeofday(>od_start_time,0);" called in other place?
In fact, what is the different between gtod_start_time and gtod_now_time?
Ok sorry, I missed that. gtod_start_time is a member variable of the class and set in the constructor. If it's instantiated at program start time, this method will return milliseconds since the start of the program. If you really need milliseconds since the start of the system, you might need to write a small program which dumps the gettimeofday value to a text file at boot time (called in /etc/init.d/rc3.d, or whatever runlevel), which is then read once by your code, etc. etc. There may be other ways, but that is the only way I can think of now.
Quote:
[i]
GetTickCount return millisecond (in window original function)but tv_usec return microsecond(in linux time.h). micro=1/1000milli. is it "*1000" not "/1000"?
Look at it again, the unit you want is milliseconds.
OH, I see.
Thank you very much.
Are there any log files that the Linux will record the time when the linux system startup? If I am right, I remember that everytime the Linux will record any processes in a log file just like a command of "history".
Do you know where can I find out more information about timer in Linux? I found some Linux books but they talk less about it.
Sorry that I have lots of questions.
No idea about the logs, but you may want to take a look at /var/log directory. A simple shell script containing something like "echo $(/sbin/hwclock) > /tmp/starttime.txt" and invoked at start time via a symlink in /etc/init.d/rc[n].d may also do the trick.
BTW when I'm looking for *NIX aquivalents of windows interfaces, my first try generally is asking google for something like "<name_of_windows_api> linux"
oh, thanks.
thank you for your useful information.
I have an other additional question.
do you know Mfc Macros ?
I have a problem about the rewrite of IMPLEMENT_DYNCREATE(), DECLARE_DYCREATE() and DECLARE_DYNAMIC().
Can you give me some ideas about it?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Well, Linux is (or some Linux distros are) rotating or clearing /var/log/wtmp every month, which is questionable (Unix keep the file intact).
Anyway, you can overcome it by pointing "last" to a more persistent file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.