1

I have the following code:

#include <stdio.h>

int main() {
    for (size_t i = 0; i < 100000; i++)
    {
        printf("%zu ", i);
        if(i == 10)
            getchar();
    }
}

When this executable is built and profiled in Windows with Visual Studio IDE integration, clicking on the start button within VTune opens a console window where I am able to see the printing of the numbers including waiting for user input from the getchar(); command.

I am unable to get this similar functionality in Ubuntu. I open VTune profiler via running the following script in Ubuntu:

source "/opt/intel/oneapi/vtune/latest/env/vars.sh" && vtune-gui --project-path "/home/TryerGit/GoogleDrive/research_programming/debugtesting/VTune/vtune" --app-path "/home/TryerGit/GoogleDrive/research_programming/debugtesting/VTune/.vscode/dist/Release/GNU-Linux/linux"

After this, VTune app opens up but when the Start profiling button is pressed, where exactly can one interact with the executable? Where, for e.g., would the printf statements go and where can one press a character in response to getchar();?


Intel folks confirmed that this seems to be a bug in VTune. A workaround was provided here

Tryer
  • 3,580
  • 1
  • 26
  • 49
  • @A4F9 The question is not about `%d` vs `%lu`. It is about VTune profiler opening the executable in a separate terminal so that one can interact with the executable via the terminal. – Tryer Feb 21 '23 at 14:18
  • @Tryer so he only commented not answered. Your code invokes UB. – 0___________ Feb 21 '23 at 14:21
  • 1
    If VTune does not open a new window for the execution of the program under test, then my expectation would be that it is connected to the same one from which VTune itself was launched. It is possible that there is a way to request that a new window be created, but I have no familiarity with this tool on which to rely for any specific recommendation. To be clear: it is VTune that would need to provide such a separate-window feature. I see no reason to think that you could produce such an effect externally. – John Bollinger Feb 21 '23 at 14:46
  • @JohnBollinger Your intuition is correct. If I remove the `getchar();` lines, in the same terminal from which I launched the script in the OP, the numbers are displayed. But this is a rather suboptimal way to profile the executable -- it seems to indicate that there cannot be any user input in linux while in Windows, it is possible to have user interaction. FWIW, I have raised a query with Intel folks as well [here](https://community.intel.com/t5/Analyzers/bd-p/analyzers) , I hope something comes of it! – Tryer Feb 21 '23 at 14:54
  • @Tryer, if the program's standard output is connected to the original terminal then I would expect its standard input to be, too. That wouldn't *have* to be the case, but it's what you would get as a default if neither VTune nor the the program under test did anything to produce a different effect. – John Bollinger Feb 21 '23 at 15:00
  • @JohnBollinger When I run the program standalone (via `./linux` in the folder in which my makefile instructs it to be built) in a terminal, the printfs and the getchar work -- former in the terminal and the latter gets it input from the keyboard. What is susprising is that in the example with the getchar, on launching the executable via VTune profiler, it is not even the case that numbers 1 through 10 are printed in the same terminal from which the script was run for it is only after that that I have to enter a character due to getchar() – Tryer Feb 21 '23 at 15:09
  • @Tryer, that has little to do with where the input and output are connected. The standard output is *buffered* by default -- specifically, *line* buffered when connected to an interactive device -- so output does not necessarily appear immediately after you send it. Add an `fflush(stdout)` after your `printf()` to force the numbers to appear immediately, or add a newline at the end of the format string. This is a C thing, not really anything to do with VTune. – John Bollinger Feb 21 '23 at 15:18
  • @JohnBollinger Even with `\n` or `fflush( ... )`, the issue remains -- presence of `getchar();` seems to prevent output in the terminal and user input don't seem possible from within VTune. – Tryer Feb 21 '23 at 15:33
  • That seems pretty unlikely to me, @Tryer, but I can't test it for myself. You could consider running the program directly, without VTune, to see how its behavior differs under those circumstances. If there actually is some kind of flaw in VTune, then the fact that the program behaves different when running under VTune's control would be central to that. – John Bollinger Feb 21 '23 at 15:39
  • Seems like you have raised a thread in Intel Communities i.e https://community.intel.com/t5/Analyzers/Getting-VTune-Profiler-to-open-the-executable-in-a-separate/m-p/1457870#M23009 As a workaround, Please run the Vtune analysis using CLI and view the results on GUI. – Jaideep - Intel Feb 27 '23 at 10:12

0 Answers0