I have a host application and I have written a plug-in. I compile my plug-in down to a shared object (say foo.so), and the host application will load it via dlopen. In this case, my host application is the opt tool from llvm (though I don't think that's important to the question).
I'd like to compile my plug-in with profiling enabled (i.e. g++ -pg, gprof). However, when I do this, the profile output file gmon.out is never created. Maybe gprof expects someone to call a setup routine, or something like that.
For various reasons, I would like to avoid recompiling the host app with -pg. I am curious if it is possible to profile a shared object foo.so without profiling the host application opt.
I've also looked into other profiling tools; qprof from HP should be able to handle this situation, but it is unable to resolve the names of functions in the shared object (it falls back to addr2line in a very naive way).
Thanks,
Nick
I assume the reason you want to do this is to find ways to optimize the plugin (as opposed to just getting timing information).
Can you run the host app under a debugger or IDE? Does the IDE have a pause button, or can you interrupt it with Ctrl-C or some such key?
Then you can quickly find the costly code by using this technique. Only take samples when your plugin is running, or if you can't do that, just ignore samples that don't end in your plugin.
Even if you get gprof to work, or a similar profiler, you're likely to be disappointed.
Related
Context
I'm trying to implement a sort-of orchestrator pattern for our applications.
Basically, we have three different and independent applications developped in Qt that communicate with each other using Web Socket. We'll call them "core", "business" and "ui". This is a flexibility aim as we can simply develop a new application in a more suiting technology and connect it to the others via the same communication protocole.
Now the idea is to have a simple launcher that allows us to specify which part to start. We launch this "orchestrator-like" application and it starts all required processes from a configuration file.
Everything is done in Qt currently (QML for the UI interfaces).
Initial Issue
I've made a custom class oriented towards reading the configuration file, preparing the processes, and starting them with their respective arguments.
This uses a std::map of QProcess related to their name in the configuration file and launch them using QProcess::start(<process_path>) method.
The catch is that everything went smoothly until recently. The sub processes are started and runs perfectly ; everything goes on as normal until we reach some point were the "ui" part crashes (usually an LLVM memory error or vector:: length error).
At first we thought about a memory leak or a code error but after much debugging we found that the application had no error whatsoever when we ran each part individually (without using the custom orchestrator class).
Question / Concerns
So, our question is: could it be that the QProcess:start() method actually shares the same stack with its parent? Three processes having the same parent, it would not be surprising than a vector of ~500 elements stored in each application can exceed the stack size when returned.
Information
We use MacOS Big Sur, IDE is Qt Creator, using Qt 5.15.0 and C++11.
Tried using valgrind but as read here and here, this seems a dead-end for now. The errors below were seen in the .crash file following the application exit.
libc++abi: terminating with uncaught exception of type std::length_error: vector
ui(2503,0x108215e00) malloc: can't allocate region :*** mach_vm_map(size=140280206704640, flags: 100) failed (error code=3) ui(2503,0x108215e00) malloc: *** set a breakpoint in malloc_error_break to debug LLVM ERROR: out of memory
Also tried to redirects or completly remove the application's output. First changing the setProcessChannelMode when starting the application, then with startDetached instead of start. Then, commented my Log method dumping log info into the corresponding Qt output (info/warning/critical/fatal/debug).
As suggested by #stanislav888, we could rewrite the application manager part in bash scripts and it would probably do the trick but I'd like to understand the root issue to avoid future mistakes.
It looks like a bad design. Application running and orchestrating through bash or PowerShell script looks much more better.
But anyway.
You could try to suppress orchestrated applications output and see what happen. The programs output might flood memory and make crash.
You must check what particular trouble cause the crash. Use memory "coredump" and system error messages to understand the all problem details.
I sure the community need that details. Because "оut of memory", "stack depth exceeded" and same errors make big difference.
Try to write bash or PowerShell script which does the same workflow as the Qt application. Hope it is not hard. But it will help you to figure out the issue.
At least you can run this script from the application.
We are using the Telerik RadEditor control, specifically for it's ability to render a PDF via the ExportToPDF() method on the control. We find that this works great in our development and test environments but fails as soon as we get to our client's environment. What I mean by fails is that typically when you execute the ExportToPDF() method, a dialog box pops up with the name of the PDF file, it's size, and whether you want to open it or save it. In our client's environment that dialog window appears, but the file size does not appear. If you save the file, it's a blank document. The machines / environments are equal in their setup (IIS 6 on Windows server 2003). The only exception is that our client's machine is in a secure environment with no access to the internet.
We are loading form letters into the control and then creating the PDF once the user clicks a button, so I don't think this is being caused by bad data / invalid characters causing the PDF not to generate.
My questions are: does anyone have experience running the ExportToPDF() command in an environment with no access to the internet? Could this be a permissions issue? I can't seem to find documentation on whether the ExportToPDF() functionality uses a temporary directory to write the PDF out to while it's rendering. It may be as simple as that, but I'm having a hard time researching this issue.
I've also put a try / catch block around the ExportToPDF() method and I know it's not throwing any errors.
We are running an older version of RadEditor - 2009.3.1208 - it runs in a large application with other Telerik tools so upgrading the entire RadControl suite is not trivial (b/c of testing, etc) and is taking some time.
Any suggestions on what to try next / has anyone encountered anything like this with this control?
Thanks for your help in advance!
Richard
I doubt that the export functionality needs an active internet connection. Most likely something in your secured environment is blocking silently the export and it does not simply happen. My recommendation is to check the permissions/processes you have on the user machine and test the same outside of the local environment to compare the results.
I use a third-party DLL (FTD2xx) to communicate with an external device. Using Qt4, in debug mode everything works fine, but the release crashes silently after successfully completing a called function. It seems to crash at return, but if I write something to the console (with qDebug) at the end of the function, sometimes it does not crash there, but a few, or few dozen lines later.
I suspect a not properly cleaned stack, what the debug build can survive, but the release chokes on it. Did someone encounter a similar problem? The DLL itself cannot be changed, as the source is not available.
It seems the reduction of the optimization level was the only way around. The DLL itself might have problems, as a program which does nothing but calls a single function from that DLL crashes the same way if optimization is turned on.
Fortunately, the size and speed lost by the change in optimization level is negligible.
Edit: for anyone with similar problems on Qt 5.0 or higher: If you change the optimization level (for example, to QMAKE_CXXFLAGS_RELEASE = -O0), it's usually not enough to just rebuild the application. A full "clean all" is required.
Be warned - the EPANET library is not thread safe, it contains a lot of global variables.
Are you calling two methods of that library from different threads?
Is it possible to run Google NaCl outside of the browser as a process sandbox?
Yes. The standalone build of Native Client contains a program called "sel_ldr" which runs the NaCl sandbox outside of the web browser. A lot of NaCl's test suite tests NaCl by running programs under sel_ldr rather than under the browser.
The Native Client documentation is probably a good starting point for trying to figure out how everything works.
As Mark Seaborn and Bennet Yee indicate, you are probably best off looking into using sel_ldr. More details about how sel_ldr is included in "The life of sel_ldr".
I haven't personally implemented anything that uses NaCl outside of a browser, so I can't unfortunately comment on the ease of doing so.
To add to Mark's answer, take a look at the sel_universal target. There are obviously some interfaces that cannot be supported, e.g., Pepper interfaces, since such a stand-alone run doesn't involve a browser. Furthermore, the stable ABI that we support is that which is exposed by the "integrated runtime" or irt, and the irt code thunk assumes that the browser is present. a standalone use of NaCl via sel_ldr would probably have to use the syscall interface initially, until an alternate irt is written. (NB: we make no guarantees about the stability of the syscall interface.)
You can try run.py which included in Native Client's source.
Here is an example that runs a hello world program.
make test_hello_world_nexe
python native_client/run.py out/Debug/hello_world_newlib_x64.nexe
This script can build, search and invoke sel_ldr, and pass proper arguments to it automatically.
I'm new to web development so please, could you help me to understand if I'm working in the right direction?
There will be a webpage intended for our customers (not intranet) from where they can print labels. Some of the larger customers will have special label printers where configuration and printing using COM-port is the only acceptable option. Basically we have very limited knowledge and control over their environment.
The web-page itself will be a pretty simple html-page or more complex AJAX.
After the customer inputs all the data and happens to chose this type of printing we have following tasks:
1) get data about the printers on the customer's system installed to a comport and if possible get printer settings (like paper size and orientation). Ideally would like to be able to adjust the settings, but if it is a pain can just put into requirements that your printer must be installed to COM1 and configured correctly.
2) send commands and read answers and send PCL code to the selected com port
As I understand I'll need to install something on the customer's machine to be able to talk to com port and get any settings. Just HTML+Javascript are not capable of doing that. Right?
I found RXTX library which seems to communicate to com port on most platforms. Can it be called from JavaScript or I still need to do a Java plugin? Are there technologies other than Java plugin that would solve the task?
The web-page will be used in different environment - platforms and web-browsers. We would like to minimize the number of customized solutions. Will Java allow us to do the same plugin for all environments with minimal customization?
If we require the user to install a plugin will the user be prompted with our credentials to confirm the installation? Will our web-site require higher trust settings?
Thanks for you help!
Well, I've had to do this in the past. Here is what I did and the circumstances
1) I knew that our customers were in a windows environment so I wrote win32 software to handle the printing.
2) I created a file format to be read by the win32 software that allowed me to specify print parameters and the label data. XML works ok for things like this.
3) My web app created a file in the format used by the win32 software and returned it to the user when they clicked on the "Print Labels" button. The file extension on the file returned was registered by the installer of the win32 software. That means when their browser looked for a default app handler for that file, it found my win32 software.
Bottom line is that the browser is handing off the printer communications to a native application instead of talking directly to the printer.
Obviously you need to be able to dictate your end user's are using a windows machine (or mac or whatever you can write native code). Associating a file extension with my program and returning that file to the user was the key to making the process work for me.
Whether your native code sends pcl directly to the printer or translates into a print api (like the win32 api as mine does) is another consideration.
Another approach you could consider is instead of sending PCL codes, you could create a PDF of the document. Format the document to the size and orientation of the label printer. The user will still have to hit the print button, but that might work. I have done this for printing to bar code printers and it works fine. Sometimes getting the margin and orientation correct is a little tricky, but that can be figured out.