-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
47 lines (40 loc) · 1.05 KB
/
example.cpp
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
// Copyright (c) 2017, Raffaele Solcà
// All rights reserved.
//
// See LICENSE.txt for terms of usage.
#include "profiler.h"
#include <iostream>
#include <future>
#include <thread>
void test(int thr_id, std::string name, std::string group) {
profiler::GenericTaskProfiler tp(thr_id, name, group);
sleep(1);
}
int main() {
profiler::Profiler::getProfiler().setOutputFilename("output_file.csv");
{
std::vector<std::future<void>> fts;
for (int i = 0; i < 10; ++i) {
fts.emplace_back(std::async(test, i, "Task " + std::to_string(i), "Group1"));
}
for (auto& ft : fts)
ft.get();
}
{
std::vector<std::future<void>> fts;
for (int i = 0; i < 10; ++i) {
fts.emplace_back(std::async(test, i, "AnotherTask " + std::to_string(i), "Group2"));
}
for (auto& ft : fts)
ft.get();
}
{
std::vector<std::future<void>> fts;
for (int i = 0; i < 10; ++i) {
fts.emplace_back(std::async(test, i, "ExtraTask " + std::to_string(i), "Group1"));
}
for (auto& ft : fts)
ft.get();
}
return 0;
}