File: test.cpp

package info (click to toggle)
vart 2.5-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,404 kB
  • sloc: cpp: 30,188; python: 7,493; sh: 969; makefile: 37; ansic: 36
file content (79 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright 2021 Xilinx Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <thread>
#include <vector>
#include <vitis/ai/trace.hpp>

#define N_LOOP (100000)
#define N_THREAD (5)

using namespace std;

void trace_thread(int id, size_t nloop) {
  cout << "id: " << id << " Thread start!" << endl;
  for (size_t i = 0; i < nloop; i++) {
    if (i % 20000 == 0) cout << "Thread " << id << ": Loop: " << (i/1000) << 'K' << endl;
    if (((id % 2) == 0) == true) {
      vitis::ai::trace::add_trace("Thread_1", i, 3.3, 'd', "hello");
    } else {
      vitis::ai::trace::add_trace("Thread_2", i * 8, 3.3, 'd', "world");
    }
  }
}

int main(int argc, char* argv[]) {
  size_t nth = N_THREAD;
  size_t nloop = N_LOOP;
  using Clock = std::chrono::steady_clock;

  if (argc == 3) {
    nth = atoi(argv[1]);
    nloop = atoi(argv[2]);
  };

  // vitis::ai::trace::initialize(4);
  vector<thread> ths;

  vitis::ai::trace::new_traceclass("Thread_1", {"morning", "noon", "night"});
  vitis::ai::trace::new_traceclass("Thread_2",
                                   {"spring", "summer", "autumn", "winter"});

  for (size_t i = 0; i < 20; i++) {
    vitis::ai::trace::add_info("Thread_1", "time", i++, "school", 987);
    vitis::ai::trace::add_info("Thread_2", "time", i++, "school", 876);
  }

  auto start = Clock::now();
  for (size_t i = 0; i < nth; i++) {
    auto t = thread(trace_thread, i, nloop);
    ths.push_back(move(t));
  }

  for (size_t i = 0; i < nth; i++) {
    ths[i].join();
  }

  auto end = Clock::now();
  std::chrono::duration<double> elapsed_seconds = end - start;
  auto entry_num = nth * nloop;
  cout << "Total trace entries: " << entry_num << endl;
  cout << "Elapsed time: " << elapsed_seconds.count() << " s\n";
  auto tpt = elapsed_seconds.count() * 1000 * 1000 / entry_num;
  cout << "Time per trace: " << tpt << " us" << endl;

  return 0;
}