I was looking through stackoverflow for the best profiling technique.
I have a bunch of processes running 24/7, written in C and using Oracle 10g. I have discovered several tools I want to try: oprofile, strace, systemtap and dtrace.
I want to start with dtrace and thus I was looking for some simple dtrace script that will connect to running process' and print out all function calls, time spent in each ... maybe callgraph. Please, suggest some good script to start with, any links, tutorials, manuals.
Simple. No DTrace on Linux (last I heard).
If you crave for DTrace and are willing to give a real operating system a try (uh-oh, flamebait :-), try FreeBSD which comes with a functional and integrated DTrace.
Related
I want to find CPU usage of my own c application.
I have already use ps -p pid -o %cpu,%mem,cmd It works fine in my Ubuntu 10.04 desktop. But not work in ARM architecture.
It shows following error.
ps: invalid option -- 'p'
BusyBox v1.13.2 (2011-03-24 18:58:44 CDT) multi-call binary
Usage: ps
Report process status
Options:
w Wide output
So I need c code for finding cpu usage.
Busybox is a small footprint set of tools which only contains the most useful subset of the functionality you will find in a desktop system.
For a more complete ps you might want to use the ps from http://procps.sourceforge.net/
You might want to replace the ps in busybox, or you could take snippets of C source from procps if your program has a GPL compatible license.
Busybox also provides "top", which can display the CPU usage of processes.
This doesn't directly answer your question since it's not using C, but maybe it will solve your problem without the extra hassle since you were already willing to use ps.
If you want to measure CPU time and if you're on a (mostly) POSIX-supporting platform (maybe Android?), then you should look at clock_gettime() and getrusage() . You can find something to start here.
My goal is to determine when executing a command, precisely which files it reads and writes. On Linux I can do this using ptrace (with work, akin to what strace does) and on FreeBSD and MacOS I can do this with the ktrace system command. What would you use to obtain this information on Windows?
My research so far suggests that I either use the debugger interface (similar to ptrace in many ways) or perhaps ETW. A third alternative is to interpose a DLL to intercept system calls as they are made. Unfortunately, I don't have the experience to guess as to how challenging each of these approaches will be.
Any suggestions?
Unfortunately it seems there is no easy way to intercept file level operations on Windows.
Here are some hints:
you could try to use FileMon from Sysinternals if it is enough for your needs, or try to look at the source of the tool
you could make use of commercial software like Detours - beware, I never used that myself and I'm not sure it really meets your needs
If you want a better understanding and are not frightened at doing it by hand, the Windows way of intercepting file I/O is using a File System Filter Driver. In fact, there is a FilterManager embedded in Windows system that can forward all file system calls to minifilters.
To build it, the interface with the system is provided by the FilterManager, and you have just (...) to code and install the minifilter that does the actual filtering - beware again never tested that ...
As you suggested, this is a fairly simple task to solve with API hooking with DLL injection.
This is a pretty good article about the application: API hooking revealed
I believe you can find more recent articles about the issue.
However, you probably need to use C++ to implement such a utility. By the way, programs can disable DLL injection. For example, I weren't able to use this approach on the trial version of Photoshop.
So, you may want to check if you can inject DLL files in the process you want with an existing solution before you start writing your own.
Please, take a look to the article CDirectoryChangeWatcher - ReadDirectoryChangesW all wrapped up.
It is a very old, but running, way to watch directory changes.
Microsoft owns a bunch of tools called Sysinternals. There is a program called Process Monitor that will show you all the file accesses for a particular process. This is very likely what you want.
Check this particular Stack Overflow question out for your question... This might help you:
Is there something like the Linux ptrace syscall in Windows?
Also, if you are running lower versions like Windows XP then you should check out Process Monitor.
Also, I would like you to check this out...
Monitoring certain system calls done by a process in Windows
I'm into something about writing a "Mock GPU driver" for Linux based systems. What I mean is that, simply I want to write a driver (Behind X-server obviously) to answer X's API calls with some debugging messages.
In other words I want to fool Linux about having an actual GPU. So I can make a test-bed for GUI-accelerated packages in console based systems.
Right now, if I execute a GUI-accelerated package in Linux console based systems; it'll simply dies due to lack of a real GPU (or a GPU driver better I'd say).
So I want to know:
Is it even possible? (Writing a GPU driver to fool Linux about having an actual GPU)
What resources do you recommend before getting my hands dirty in code?
Is there any similar projects around the net?
PS: I'm an experienced ANSI-C programmer but I don't have any clue in real Kernel/Driver development under *nix (read some tutorials about USB driver development though), so any resources about these areas will be really appreciated as well. Thanks in advance.
What you are looking for is actually part of Xorg server suite, and it is called Xvfb (virtual framebuffer).
If you're not afraid of a bit complex bash, you can take a look at Gentoo's virtualx.eclass for an use example (we use it to run tests which require X11).
A good place to start is the Mesa project - it implements OpenGL in software. It has a way to trick the OS into thinking that it is the OpenGL driver.
I have a process that seems to be hanging on solaris, I have tried to attach to the process using GDB to see what it is doing but no luck.
There is no error from what I can see, it is just sitting there...
Are there any other tools or techniques I can use to see what the process is stuck on?
Thanks for the help
Lynton
pstack <pid> will print you what all the threads within this process are doing (full stack traces, including function names, if your binary is not stripped.
truss is Linux's strace equivalent. It will show all the system calls that the process is doing. It might help you in debugging.
DTrace is a great debugging swiss-army-knife that can show you pretty much anything you can think of. The downside is that it needs to be run with root permissions on a global zone. It takes some time to learn, but it's time well worth spending.
Use powerful dtrace facility.
Here the short introduction how to trace user processes.
I'm writing a multithreaded server using Ptrheads and I want to trace the execution of individual threads.
What would be a good tracing library for this?
cTrace is an good option.
NPTL sounds exactly like what you need. I have tried unsuccessfully to install it, though, and it seems dated a bit but the features are great. If you succeed in installing it, drop me a line through here! There is also PAPI, but it's tough to handle, and there's finally Valgrind (particularly Cachegrind) for certain subset of debugging needs. Hope this helps.