intel / pti-gpu

Profiling Tools Interfaces for GPU (PTI for GPU) is a set of Getting Started Documentation and Tools Library to start performance analysis on Intel(R) Processor Graphics easily
MIT License
202 stars 57 forks source link

[unitrace] adding my own events #53

Closed rscohn2 closed 8 months ago

rscohn2 commented 11 months ago

I want to add my own application events in unitrace. I added itt directly to my application and link against the static library.

class itt_log {
public:
  enum class task_id {
    init,
    sentinel
  };

  itt_log() {
    domain_ = __itt_domain_create("DR");
    for (std::size_t i = 0; i < num_ids_; i++) {
      handles_[i] = __itt_string_handle_create(names_[i]);
    }
  }

  void begin(task_id id) {
    __itt_task_begin(domain_, __itt_null, __itt_null, handles_[std::size_t(id)]);
  }

  void end() {
    __itt_task_end(domain_);
  }

private:
  static constexpr std::size_t num_ids_ = std::size_t(task_id::sentinel);
  __itt_domain *domain_;
  __itt_string_handle *handles_[num_ids_];
  const char *names_[num_ids_] = {"DR_Init"};
};

My test program does:

  itt_log itt;
  itt.begin(itt_log::task_id::init);
  itt.end();

The program runs, but I do not see my DR events in the json file:

idc-beta-batch-pvc-node-16:mhp$ rm -f *.json && unitrace --chrome-kernel-logging ./mhp-quick-test && cat *.json
Enable CPU
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Itt
[ RUN      ] Itt.Basic
[       OK ] Itt.Basic (0 ms)
[----------] 1 test from Itt (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[  PASSED  ] 1 test.

[INFO] Timeline is stored in mhp-quick-test.1734039.json
{ "traceEvents":[
{"ph": "X", "tid": 1734039, "pid": 1734039, "name": "zeCommandListCreateImmediate", "cat": "cpu_op", "ts": 1703435877153433, "dur": \1532, "id": 0},
{"ph": "M", "name": "process_name", "pid": 1734039, "ts": 1703435877135907, "args": {"name": "HOST<idc-beta-batch-pvc-node-16>"}}
]
}
idc-beta-batch-pvc-node-16:mhp$

Is there something more I have to do?

Sarbojit2019 commented 10 months ago

"--chrome-kernel-logging" does not enable Itt logging. As of now Unitrace does not have any option for user to enable only Itt logging. Unitrace traces itt calls as part of oneCCL, oneDNN and MPI.

There is a workaround you can try by setting environment variable "UNITRACE_ChromeIttLogging=1" as part of your launch script. Let me know if you still don't see Itt events.

rscohn2 commented 10 months ago

Setting the environment variable enables the itt logging, but I still don't see my events in the json file. I tried to trace it through but the wrappers for the itt_task_begin makes it hard to understand what should happen. I am making itt_task_begin calls directly from my application and linking with the libittnotify.a that is built by pti-gpu.

Sarbojit2019 commented 10 months ago

I will try to recreate the issue at my end and analyze it further. In case you any small sample which I can use to reproduce the issue let me know.

rscohn2 commented 10 months ago

Here is an example:

#include <ittnotify.h>

int main(int argc, char *argv[]) {
  __itt_domain *domain = __itt_domain_create("DR");
  __itt_string_handle *handle = __itt_string_handle_create("DR_Init");
  __itt_task_begin(domain, __itt_null, __itt_null, handle);
  __itt_task_end(domain);

  return 0;
}

Build:

icpx test.cpp -I ~/software/install/include ~/software/install/lib/libittnotify.a -o unitrace-test

Run:

idc-beta-batch-pvc-node-02:unitrace$ rm -f *.json && UNITRACE_ChromeIttLogging=1 unitrace ./unitrace-test && cat *.json
Checking
itt enabled
itt created
Enabling chrome for itt
Destructor

[INFO] Timeline is stored in unitrace-test.3602166.json
{ "traceEvents":[
{"ph": "M", "name": "process_name", "pid": 3602166, "ts": 1704295094529532, "args": {"name": "HOST<idc-beta-batch-pvc-node-02>"}}
]
}
idc-beta-batch-pvc-node-02:unitrace$
Sarbojit2019 commented 8 months ago

@rscohn2, We have added "--chrome-itt-logging" as option. If you are happy with the change then please close the ticket.

rscohn2 commented 8 months ago

Thanks