mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-12-21 13:07:00 +00:00
Delete old files from test/
This commit is contained in:
parent
7c1b4c2a43
commit
949f53b456
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,17 +1,7 @@
|
||||
## OI specific
|
||||
build/
|
||||
test.o
|
||||
test/tester
|
||||
test/mttest?
|
||||
test/mttest2_inline
|
||||
test/integration_mttest
|
||||
test/integration_cycles
|
||||
test/integration_sleepy
|
||||
test/integration_packed
|
||||
test/mapiter
|
||||
test/userDef1
|
||||
test/vector
|
||||
test/inlined_test
|
||||
test/.autogen-*
|
||||
oi_preprocessed
|
||||
*_test.oid
|
||||
@ -22,7 +12,6 @@ Testing
|
||||
*.o
|
||||
PADDING
|
||||
failed
|
||||
fb_*_wrapper.sh
|
||||
website/node_modules
|
||||
|
||||
## Vim
|
||||
|
@ -2,9 +2,8 @@ CXX=clang++
|
||||
CXXFLAGS=-g -fdebug-types-section -I../extern/folly -O2 -pthread -no-pie
|
||||
FILTER ?=
|
||||
|
||||
TARGETS=integration_mttest integration_sleepy integration_packed integration_cycles mapiter mttest1 mttest2 mttest2_inline mttest3 mttest4 tester userDef1 vector inlined_test
|
||||
TARGETS=integration_mttest integration_sleepy
|
||||
|
||||
mttest2_inline: CXXFLAGS+=-DMTTEST2_INLINE_DO_STUFF
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
|
31
test/TARGETS
31
test/TARGETS
@ -1,31 +0,0 @@
|
||||
load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
|
||||
|
||||
cpp_binary(
|
||||
name = "mapiter",
|
||||
srcs = ["mapiter.cpp"],
|
||||
deps = [
|
||||
],
|
||||
)
|
||||
|
||||
cpp_binary(
|
||||
name = "vector",
|
||||
srcs = ["vector.cpp"],
|
||||
deps = [
|
||||
],
|
||||
)
|
||||
|
||||
cpp_binary(
|
||||
name = "userDef1",
|
||||
srcs = ["userDef1.cpp"],
|
||||
deps = [
|
||||
],
|
||||
)
|
||||
|
||||
cpp_binary(
|
||||
name = "mttest1",
|
||||
srcs = ["mttest1.cpp"],
|
||||
deps = [
|
||||
"//common/init:init",
|
||||
],
|
||||
external_deps = [("glibc", None, "pthread")],
|
||||
)
|
@ -1,70 +0,0 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#define INLINE static inline __attribute__((always_inline))
|
||||
|
||||
template <class T>
|
||||
INLINE std::vector<T> combine(const std::vector<T>& x,
|
||||
const std::vector<T>& y) {
|
||||
std::vector<T> combined;
|
||||
combined.reserve(x.size() + y.size());
|
||||
for (auto& elem : x)
|
||||
combined.push_back(elem);
|
||||
for (auto& elem : y)
|
||||
combined.push_back(elem);
|
||||
return combined;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
INLINE std::vector<T> flatten(const std::vector<std::vector<T>>& vec) {
|
||||
std::vector<T> flattened;
|
||||
for (auto& elem : vec)
|
||||
flattened = combine(elem, flattened);
|
||||
return flattened;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
INLINE std::vector<T> flatten_combine(const std::vector<std::vector<T>>& x,
|
||||
const std::vector<std::vector<T>>& y) {
|
||||
auto x_flat = flatten(x);
|
||||
auto y_flat = flatten(y);
|
||||
return combine(x_flat, y_flat);
|
||||
}
|
||||
|
||||
#define MAX_SIZE 256
|
||||
|
||||
void fill(std::vector<int>& vec, int n) {
|
||||
n %= MAX_SIZE;
|
||||
vec.clear();
|
||||
vec.reserve(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
vec.push_back(rand());
|
||||
}
|
||||
|
||||
void fill_vec(std::vector<std::vector<int>>& vec, int n) {
|
||||
n %= MAX_SIZE;
|
||||
vec.clear();
|
||||
vec.reserve(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
vec.emplace_back();
|
||||
auto& last = vec.back();
|
||||
fill(last, rand());
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
size_t exit_code = 0;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
std::vector<std::vector<int>> x;
|
||||
std::vector<std::vector<int>> y;
|
||||
fill_vec(x, rand());
|
||||
fill_vec(y, rand());
|
||||
auto result = flatten_combine(x, y);
|
||||
for (auto value : result)
|
||||
exit_code += rand() % (value + 1);
|
||||
sleep(1);
|
||||
}
|
||||
return (int)exit_code;
|
||||
}
|
@ -1 +0,0 @@
|
||||
entry:_ZL7flattenIiESt6vectorIT_SaIS1_EERKS0_IS3_SaIS3_EE:arg0
|
@ -1 +0,0 @@
|
||||
entry:_ZL15flatten_combineIiESt6vectorIT_SaIS1_EERKS0_IS3_SaIS3_EES7_:arg0
|
@ -64,7 +64,6 @@ class OIDebuggerTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
self.custom_generated_code_file = f"{self.temp.name}/custom_oid_output.cpp"
|
||||
self.script_packed = f"{self.temp.name}/integration_packed_arg0.oid"
|
||||
self.default_script = "integration_entry_doStuff_arg0.oid"
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -1,83 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
struct RawNode {
|
||||
uint64_t value;
|
||||
struct RawNode* next;
|
||||
};
|
||||
|
||||
void __attribute__((noinline)) rawPointerCycle(struct RawNode* node) {
|
||||
for (int i = 0; node && i < 10; i++) {
|
||||
node->value++;
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
struct UniqueNode {
|
||||
uint64_t value;
|
||||
std::unique_ptr<struct UniqueNode> next;
|
||||
};
|
||||
|
||||
void __attribute__((noinline)) uniquePointerCycle(struct UniqueNode* node) {
|
||||
for (int i = 0; node && i < 10; i++) {
|
||||
node->value++;
|
||||
node = node->next.get();
|
||||
}
|
||||
}
|
||||
|
||||
struct SharedNode {
|
||||
uint64_t value;
|
||||
std::shared_ptr<struct SharedNode> next;
|
||||
};
|
||||
|
||||
void __attribute__((noinline)) sharedPointerCycle(struct SharedNode* node) {
|
||||
for (int i = 0; node && i < 10; i++) {
|
||||
node->value++;
|
||||
node = node->next.get();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr,
|
||||
"One of 'raw', 'unique', or 'shared' should be provided as an "
|
||||
"argument\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (strcmp(argv[1], "raw") == 0) {
|
||||
RawNode third{2, nullptr}, second{1, &third}, first{0, &second};
|
||||
third.next = &first;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
rawPointerCycle(&first);
|
||||
sleep(1);
|
||||
}
|
||||
} else if (strcmp(argv[1], "unique") == 0) {
|
||||
std::unique_ptr<UniqueNode> first = std::make_unique<UniqueNode>();
|
||||
UniqueNode* firstPtr = first.get();
|
||||
first->next = std::make_unique<UniqueNode>();
|
||||
first->next->next = std::make_unique<UniqueNode>();
|
||||
first->next->next->next = std::move(first);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
uniquePointerCycle(firstPtr);
|
||||
sleep(1);
|
||||
}
|
||||
} else if (strcmp(argv[1], "shared") == 0) {
|
||||
std::shared_ptr<SharedNode> first = std::make_shared<SharedNode>();
|
||||
SharedNode* firstPtr = first.get();
|
||||
first->next = std::make_shared<SharedNode>();
|
||||
first->next->next = std::make_shared<SharedNode>();
|
||||
first->next->next->next = first;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sharedPointerCycle(firstPtr);
|
||||
sleep(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"One of 'raw', 'unique', or 'shared' should be provided as an "
|
||||
"argument\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
entry:_Z15rawPointerCycleP7RawNode:arg0
|
@ -1 +0,0 @@
|
||||
entry:_Z18sharedPointerCycleP10SharedNode:arg0
|
@ -1 +0,0 @@
|
||||
entry:_Z18uniquePointerCycleP10UniqueNode:arg0
|
@ -1 +0,0 @@
|
||||
entry:badFunc:arg0
|
@ -1 +0,0 @@
|
||||
entry:_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg0,arg1
|
@ -1 +0,0 @@
|
||||
entry:_ZN3Foo11incVectSizeESt6vectorIiSaIiEE:arg0
|
@ -1 +0,0 @@
|
||||
entry:_ZN3Foo3incEv:this
|
@ -1 +0,0 @@
|
||||
global:myGlobalFoo
|
@ -1,60 +0,0 @@
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
struct Foo {
|
||||
std::vector<std::vector<std::vector<int>>> xs;
|
||||
};
|
||||
|
||||
Foo& doStuff(Foo& f) {
|
||||
std::vector<std::vector<int>> xs = {{5, 6, 7, 8}};
|
||||
f.xs.emplace_back(std::move(xs));
|
||||
return f;
|
||||
}
|
||||
|
||||
void run(long iteration_count) {
|
||||
for (long i = 0; i < iteration_count; ++i) {
|
||||
std::chrono::microseconds sleep_time{std::rand() & 0x7f};
|
||||
std::this_thread::sleep_for(sleep_time);
|
||||
|
||||
Foo f{{
|
||||
{
|
||||
{1, 2, 3},
|
||||
{4, 5, 6},
|
||||
},
|
||||
}};
|
||||
|
||||
doStuff(f);
|
||||
}
|
||||
}
|
||||
|
||||
void usage(char* prog, int exit_status) {
|
||||
std::printf("usage: %s <iteration_count> <thread_count>\n", prog);
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 3)
|
||||
usage(argv[0], EXIT_FAILURE);
|
||||
|
||||
long iteration_count = atol(argv[1]);
|
||||
if (iteration_count <= 0)
|
||||
usage(argv[0], EXIT_FAILURE);
|
||||
|
||||
int thread_count = atoi(argv[2]);
|
||||
if (thread_count <= 0)
|
||||
usage(argv[0], EXIT_FAILURE);
|
||||
|
||||
std::srand(std::time(nullptr));
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
threads.reserve(thread_count);
|
||||
for (int i = 0; i < thread_count; ++i)
|
||||
threads.emplace_back(run, iteration_count);
|
||||
|
||||
for (auto& t : threads)
|
||||
t.join();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1 +0,0 @@
|
||||
entry:_Z7doStuffR3Foo:arg0
|
@ -1,89 +0,0 @@
|
||||
#include <folly/Function.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <deque>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
// #include "common/init/Init.h"
|
||||
|
||||
static char textPad __attribute__((used));
|
||||
|
||||
struct __attribute__((__packed__)) Foo {
|
||||
char *p; /* 8 bytes */
|
||||
char c; /* 1 byte */
|
||||
long x; /* 8 bytes */
|
||||
};
|
||||
|
||||
// struct Foo {
|
||||
// char *p; /* 8 bytes */
|
||||
// char c; /* 8 byte */
|
||||
// long x; /* 8 bytes */
|
||||
// };
|
||||
|
||||
Foo myGlobalFoo;
|
||||
|
||||
// pass in the loop counter in the args
|
||||
int doStuff(Foo &foo) {
|
||||
return foo.x;
|
||||
}
|
||||
|
||||
void *doit(void *arg) {
|
||||
int *loopcnt = reinterpret_cast<int *>(arg);
|
||||
|
||||
for (int i = 0; i < *loopcnt; ++i) {
|
||||
Foo foo;
|
||||
foo.x = *loopcnt;
|
||||
|
||||
int result = doStuff(foo);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
}
|
||||
pthread_exit(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i = 0;
|
||||
int err;
|
||||
pthread_t tid[2];
|
||||
char *b;
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::cout << "main thread = " << syscall(SYS_gettid) << " pid = " << getpid()
|
||||
<< std::endl;
|
||||
sleep(1);
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
err = pthread_create(&(tid[i]), NULL, &doit, (void **)&loopcnt);
|
||||
|
||||
if (err != 0) {
|
||||
std::cout << "Failed to create thread:[ " << strerror(err) << " ]"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
pthread_join(tid[i], (void **)&b);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
@ -1 +0,0 @@
|
||||
entry:_Z7doStuffR3Foo:arg0
|
@ -1 +0,0 @@
|
||||
return:_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg0
|
@ -1 +0,0 @@
|
||||
return:_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:retval
|
@ -1 +0,0 @@
|
||||
return:_ZN3Foo3incEv:this
|
@ -1,58 +0,0 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::map<std::string, int> mapOfWords;
|
||||
mapOfWords.insert(std::make_pair("earth", 1));
|
||||
mapOfWords.insert(std::make_pair("moon", 2));
|
||||
mapOfWords["sun"] = 3;
|
||||
|
||||
std::vector<std::string> nameList;
|
||||
nameList.push_back("The quick brown fox");
|
||||
nameList.push_back("jumps over ");
|
||||
nameList.push_back("the ");
|
||||
nameList.push_back("lazy dog ");
|
||||
|
||||
for (auto it = nameList.begin(); it != nameList.end(); it++) {
|
||||
std::cout << "nameList: " << *it << " size: " << it->size() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
|
||||
|
||||
// std::map<std::string, int>::iterator it = mapOfWords.begin();
|
||||
// std::map<std::string, int>::iterator end = mapOfWords.end();
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
|
||||
size += it->first.size();
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
|
||||
std::cout << "nameList vector addr = " << &nameList << std::endl;
|
||||
|
||||
std::cout << "pid == " << getpid() << " (hit RETURN to continue)"
|
||||
<< std::endl;
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
std::cout << "Total size of strings in mapOfWords is " << size << " bytes"
|
||||
<< std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
146
test/mttest1.cpp
146
test/mttest1.cpp
@ -1,146 +0,0 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
// #include "common/init/Init.h"
|
||||
|
||||
static char textPad __attribute__((used));
|
||||
|
||||
// pass in the loop counter in the args
|
||||
std::vector<int> doStuff(std::vector<int> &f, int i) {
|
||||
std::vector<int> altvect = {1, 3, 5, 7};
|
||||
|
||||
std::cout << " doStuff entries: " << f.size() << std::endl;
|
||||
std::cout << " addr of f = " << reinterpret_cast<void *>(&f) << std::endl;
|
||||
|
||||
for (int j = 0; j < 40; ++j) {
|
||||
f.push_back(j);
|
||||
}
|
||||
|
||||
std::cout << " doStuff entries: " << f.size() << std::endl;
|
||||
|
||||
#if 0
|
||||
if (i % 2)
|
||||
{
|
||||
std::vector<int> altvect = { 1,3,5,7 };
|
||||
return altvect;
|
||||
/* asm("" : : "a"(altvect)); */
|
||||
/* __asm__ volatile ("movl %%rax %0"
|
||||
::"m"(altvect):); */
|
||||
/* __asm__ volatile ("retq"); */
|
||||
}
|
||||
#endif
|
||||
|
||||
std::cout << syscall(SYS_gettid) << " " << i << "f = " << std::hex << &f
|
||||
<< std::endl;
|
||||
|
||||
std::vector<int> newvect(altvect);
|
||||
|
||||
std::cout << " addr of newvect = " << reinterpret_cast<void *>(&newvect)
|
||||
<< std::endl;
|
||||
|
||||
return newvect;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void doStuff(std::vector<int> &f, int i)
|
||||
{
|
||||
f.push_back(i);
|
||||
|
||||
if (i > 1000000)
|
||||
__asm__ volatile ("retq");
|
||||
|
||||
std::cout << syscall(SYS_gettid) << " " << i
|
||||
<< "f = " << std::hex << &f << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *doit(void *arg) {
|
||||
int *loopcnt = reinterpret_cast<int *>(arg);
|
||||
std::vector<int> f;
|
||||
|
||||
for (int i = 0; i < *loopcnt; ++i) {
|
||||
std::vector<int> g = doStuff(f, i);
|
||||
|
||||
std::cout << "Number of elems = " << g.size() << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
|
||||
f.clear();
|
||||
}
|
||||
|
||||
pthread_exit(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i = 0;
|
||||
int err;
|
||||
pthread_t tid[2];
|
||||
char *b;
|
||||
|
||||
// facebook::initFacebook(&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::cout << "main thread = " << syscall(SYS_gettid) << " pid = " << getpid()
|
||||
<< std::endl;
|
||||
sleep(1);
|
||||
|
||||
std::map<std::string, int> mapOfWords;
|
||||
mapOfWords.insert(std::make_pair("earth", 1));
|
||||
mapOfWords.insert(std::make_pair("moon", 2));
|
||||
mapOfWords["sun"] = 3;
|
||||
|
||||
std::vector<std::string> nameList;
|
||||
nameList.push_back("The quick brown fox");
|
||||
nameList.push_back("jumps over ");
|
||||
nameList.push_back("the ");
|
||||
nameList.push_back("lazy dog ");
|
||||
|
||||
for (auto it = nameList.begin(); it != nameList.end(); it++) {
|
||||
std::cout << "nameList: " << *it << " size: " << it->size() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
|
||||
size += it->first.size();
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
|
||||
std::cout << "nameList vector addr = " << &nameList << std::endl;
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
err = pthread_create(&(tid[i]), NULL, &doit, (void **)&loopcnt);
|
||||
|
||||
if (err != 0) {
|
||||
std::cout << "Failed to create thread:[ " << strerror(err) << " ]"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
pthread_join(tid[i], (void **)&b);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
254
test/mttest2.cpp
254
test/mttest2.cpp
@ -1,254 +0,0 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <deque>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "mttest.h"
|
||||
// #include "common/init/Init.h"
|
||||
|
||||
static char textPad __attribute__((used));
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} UN;
|
||||
typedef UN UN2;
|
||||
typedef struct {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} ST;
|
||||
typedef ST ST2;
|
||||
|
||||
class FooParent {
|
||||
int aa;
|
||||
};
|
||||
|
||||
class Foo : FooParent {
|
||||
public:
|
||||
bool aBool;
|
||||
short aShort;
|
||||
std::vector<std::string, std::allocator<std::string>> vectorOfStr;
|
||||
std::multimap<int, int> intToStrMultiMap;
|
||||
std::map<int, int, custom_cmp> map;
|
||||
std::unordered_map<OIDTestingTwoString, int, customHash, customTwoStringEq>
|
||||
unorderedMap;
|
||||
char arr[10];
|
||||
int aa;
|
||||
int bb : 1;
|
||||
int : 0;
|
||||
int cc : 5;
|
||||
int dd : 30;
|
||||
|
||||
// Bar bar_arr[5];
|
||||
int ref;
|
||||
std::function<void(int)> testFunc;
|
||||
std::deque<int> testDeque;
|
||||
|
||||
std::queue<int, std::vector<int>> testQueue;
|
||||
};
|
||||
|
||||
Foo myGlobalFoo;
|
||||
// std::unique_ptr<Foo> myGlobalFoo;
|
||||
|
||||
// pass in the loop counter in the args
|
||||
#ifdef MTTEST2_INLINE_DO_STUFF
|
||||
static inline __attribute__((always_inline))
|
||||
#endif
|
||||
std::vector<int>
|
||||
doStuff(Foo &foo, std::vector<std::map<std::string, std::string>> &m,
|
||||
std::vector<std::string> &f,
|
||||
std::vector<std::pair<std::string, double>> &p) {
|
||||
std::vector<int> altvect = {1, 3, 5, 7};
|
||||
foo.ref++;
|
||||
myGlobalFoo.vectorOfStr.push_back(std::string("Test String"));
|
||||
|
||||
std::cout << " doStuff entries: " << f.size() << std::endl;
|
||||
std::cout << " addr of f = " << reinterpret_cast<void *>(&f) << std::endl;
|
||||
std::cout << " addr of m = " << reinterpret_cast<void *>(&m) << std::endl;
|
||||
std::cout << " addr of p = " << reinterpret_cast<void *>(&p) << std::endl;
|
||||
std::cout << " addr of myGlobalFoo = "
|
||||
<< reinterpret_cast<void *>(&myGlobalFoo) << std::endl;
|
||||
|
||||
std::vector<int> newvect(altvect);
|
||||
|
||||
std::cout << " addr of newvect = " << reinterpret_cast<void *>(&newvect)
|
||||
<< std::endl;
|
||||
|
||||
return newvect;
|
||||
}
|
||||
|
||||
void doStuff(std::vector<int> &f, int i) {
|
||||
f.push_back(i);
|
||||
std::cout << "Entries in f: " << f.size() << std::endl;
|
||||
}
|
||||
|
||||
void doNothing() {
|
||||
std::cout << "I do nothing, the function does nothing" << std::endl;
|
||||
}
|
||||
|
||||
void *doit(void *arg) {
|
||||
doNothing();
|
||||
int *loopcnt = reinterpret_cast<int *>(arg);
|
||||
std::vector<std::string> f;
|
||||
f.reserve(200);
|
||||
std::vector<std::unordered_map<std::string, std::string>> mv;
|
||||
|
||||
std::unordered_map<std::string, std::string> m;
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] = "ba";
|
||||
m["a"] = "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] =
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbaaaaaaaaaaa"] = "bbb";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccaaaaaaaa"] = "bbbb";
|
||||
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
|
||||
std::vector<std::pair<std::string, double>> pv;
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdef", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghi", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
|
||||
for (int i = 0; i < *loopcnt; ++i) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back("abcdefghijklmn");
|
||||
}
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back(
|
||||
"abcdefghijklmnoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
}
|
||||
Foo foo;
|
||||
|
||||
std::multimap<int, int> mm;
|
||||
|
||||
mm.insert(std::pair<int, int>(0, 0));
|
||||
mm.insert(std::pair<int, int>(1, 10));
|
||||
mm.insert(std::pair<int, int>(2, 20));
|
||||
mm.insert(std::pair<int, int>(3, 30));
|
||||
|
||||
mm.insert(std::pair<int, int>(1, 100));
|
||||
|
||||
foo.intToStrMultiMap = mm;
|
||||
|
||||
/*foo.vectorOfStr = f;
|
||||
foo.mapOfStr = mv;
|
||||
foo.vectorOfPair = pv;*/
|
||||
/*foo.bar_arr[0].bar = "";
|
||||
foo.bar_arr[1].bar = "0123456789";
|
||||
foo.bar_arr[2].bar = "01234567890123456789";
|
||||
foo.bar_arr[3].bar = "0123456789012345678901234567890123456789";
|
||||
foo.bar_arr[4].bar =
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456789";*/
|
||||
|
||||
foo.testFunc = [](int n) { std::cout << n << std::endl; };
|
||||
foo.testQueue.push(1);
|
||||
foo.testQueue.push(2);
|
||||
foo.testQueue.push(3);
|
||||
|
||||
foo.testDeque.push_back(5);
|
||||
|
||||
std::vector<std::map<std::string, std::string>> dummy;
|
||||
std::vector<int> g = doStuff(foo, dummy, f, pv);
|
||||
doStuff(g, i);
|
||||
|
||||
std::cout << "Number of elems = " << g.size() << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
|
||||
f.clear();
|
||||
}
|
||||
|
||||
pthread_exit(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i = 0;
|
||||
int err;
|
||||
pthread_t tid[2];
|
||||
char *b;
|
||||
|
||||
// facebook::initFacebook(&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::cout << "main thread = " << syscall(SYS_gettid) << " pid = " << getpid()
|
||||
<< std::endl;
|
||||
sleep(1);
|
||||
|
||||
std::map<std::string, int> mapOfWords;
|
||||
mapOfWords.insert(std::make_pair("earth", 1));
|
||||
mapOfWords.insert(std::make_pair("moon", 2));
|
||||
mapOfWords["sun"] = 3;
|
||||
|
||||
std::vector<std::string> nameList;
|
||||
nameList.push_back("The quick brown fox");
|
||||
nameList.push_back("jumps over ");
|
||||
nameList.push_back("the ");
|
||||
nameList.push_back("lazy dog ");
|
||||
|
||||
for (auto it = nameList.begin(); it != nameList.end(); it++) {
|
||||
std::cout << "nameList: " << *it << " size: " << it->size() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
|
||||
size += it->first.size();
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
|
||||
std::cout << "nameList vector addr = " << &nameList << std::endl;
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
err = pthread_create(&(tid[i]), NULL, &doit, (void **)&loopcnt);
|
||||
|
||||
if (err != 0) {
|
||||
std::cout << "Failed to create thread:[ " << strerror(err) << " ]"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
pthread_join(tid[i], (void **)&b);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
@ -1 +0,0 @@
|
||||
entry:_Z4doitPv:arg0
|
@ -1 +0,0 @@
|
||||
entry:_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg0
|
@ -1,14 +0,0 @@
|
||||
// Comment exemple at the start of a line
|
||||
/* Single-line comment */
|
||||
/* Multi-lines
|
||||
* comment
|
||||
*/
|
||||
/* ****** **//**//***/
|
||||
/*//*/
|
||||
// /*
|
||||
// */
|
||||
entry:/* Within-line comment */_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg2 // Comment at the end of a line
|
||||
// End of probe list
|
||||
/* No more probes
|
||||
* to see
|
||||
* here */
|
@ -1 +0,0 @@
|
||||
entry :_Z7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg0
|
@ -1 +0,0 @@
|
||||
mttest2.cpp
|
@ -1 +0,0 @@
|
||||
entry:_ZL7doStuffR3FooRSt6vectorISt3mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_St4lessIS8_ESaISt4pairIKS8_S8_EEESaISF_EERS1_IS8_SaIS8_EERS1_ISB_IS8_dESaISM_EE:arg0
|
233
test/mttest3.cpp
233
test/mttest3.cpp
@ -1,233 +0,0 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
// #include "common/init/Init.h"
|
||||
|
||||
static char textPad __attribute__((used));
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} UN;
|
||||
typedef UN UN2;
|
||||
typedef struct {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} ST;
|
||||
typedef ST ST2;
|
||||
|
||||
// typedef struct vec_struct VEC;
|
||||
|
||||
struct vec_struct {
|
||||
std::vector<int> v;
|
||||
};
|
||||
|
||||
class BaseFoo {
|
||||
int base[64];
|
||||
};
|
||||
|
||||
enum Color { Red, Green, Blue };
|
||||
|
||||
#define DIM 3
|
||||
|
||||
class Foo : BaseFoo {
|
||||
public:
|
||||
enum Color { red, green, blue } col;
|
||||
ST a[8][8];
|
||||
vec_struct b[DIM][DIM][DIM];
|
||||
Color color;
|
||||
char c[10];
|
||||
// VEC d[10];
|
||||
std::unique_ptr<ST> ptr;
|
||||
std::shared_ptr<ST> ptr2;
|
||||
std::vector<std::string> vectorOfStr;
|
||||
std::vector<std::map<std::string, std::string>> mapOfStr;
|
||||
std::vector<std::pair<std::string, double>> vectorOfPair;
|
||||
UN unionVar;
|
||||
UN2 unionVar2;
|
||||
ST structVar;
|
||||
ST2 structVar2;
|
||||
int ref;
|
||||
};
|
||||
|
||||
// pass in the loop counter in the args
|
||||
std::vector<int> doStuff(Foo &foo,
|
||||
std::vector<std::map<std::string, std::string>> &m,
|
||||
std::vector<std::string> &f,
|
||||
std::vector<std::pair<std::string, double>> &p) {
|
||||
std::vector<int> altvect = {1, 3, 5, 7};
|
||||
foo.ref++;
|
||||
|
||||
std::cout << " doStuff entries: " << f.size() << std::endl;
|
||||
std::cout << " addr of f = " << reinterpret_cast<void *>(&f) << std::endl;
|
||||
std::cout << " addr of m = " << reinterpret_cast<void *>(&m) << std::endl;
|
||||
std::cout << " addr of p = " << reinterpret_cast<void *>(&p) << std::endl;
|
||||
|
||||
std::vector<int> newvect(altvect);
|
||||
|
||||
std::cout << " addr of newvect = " << reinterpret_cast<void *>(&newvect)
|
||||
<< std::endl;
|
||||
|
||||
return newvect;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void doStuff(std::vector<int> &f, int i)
|
||||
{
|
||||
f.push_back(i);
|
||||
|
||||
if (i > 1000000)
|
||||
__asm__ volatile ("retq");
|
||||
|
||||
std::cout << syscall(SYS_gettid) << " " << i
|
||||
<< "f = " << std::hex << &f << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *doit(void *arg) {
|
||||
int *loopcnt = reinterpret_cast<int *>(arg);
|
||||
std::vector<std::string> f;
|
||||
std::vector<std::map<std::string, std::string>> mv;
|
||||
|
||||
std::map<std::string, std::string> m;
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] = "ba";
|
||||
m["a"] = "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] =
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbaaaaaaaaaaa"] = "bbb";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccaaaaaaaa"] = "bbbb";
|
||||
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
|
||||
std::vector<std::pair<std::string, double>> pv;
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdef", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghi", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
|
||||
Foo foo;
|
||||
|
||||
for (int i = 0; i < DIM; i++) {
|
||||
for (int j = 0; j < DIM; j++) {
|
||||
for (int k = 0; k < DIM; k++) {
|
||||
int elems = i * DIM * DIM + j * DIM + k;
|
||||
for (int m = 0; m < elems; m++) {
|
||||
foo.b[i][j][k].v.push_back(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < *loopcnt; ++i) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back("abcdefghijklmn");
|
||||
}
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back(
|
||||
"abcdefghijklmnoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
}
|
||||
|
||||
foo.vectorOfStr = f;
|
||||
foo.mapOfStr = mv;
|
||||
foo.vectorOfPair = pv;
|
||||
|
||||
std::vector<int> g = doStuff(foo, mv, f, pv);
|
||||
|
||||
std::cout << "Number of elems = " << g.size() << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
|
||||
f.clear();
|
||||
}
|
||||
|
||||
pthread_exit(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i = 0;
|
||||
int err;
|
||||
pthread_t tid[2];
|
||||
char *b;
|
||||
|
||||
// facebook::initFacebook(&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::cout << "main thread = " << syscall(SYS_gettid) << " pid = " << getpid()
|
||||
<< std::endl;
|
||||
sleep(1);
|
||||
|
||||
std::map<std::string, int> mapOfWords;
|
||||
mapOfWords.insert(std::make_pair("earth", 1));
|
||||
mapOfWords.insert(std::make_pair("moon", 2));
|
||||
mapOfWords["sun"] = 3;
|
||||
|
||||
std::vector<std::string> nameList;
|
||||
nameList.push_back("The quick brown fox");
|
||||
nameList.push_back("jumps over ");
|
||||
nameList.push_back("the ");
|
||||
nameList.push_back("lazy dog ");
|
||||
|
||||
for (auto it = nameList.begin(); it != nameList.end(); it++) {
|
||||
std::cout << "nameList: " << *it << " size: " << it->size() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
|
||||
size += it->first.size();
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
|
||||
std::cout << "nameList vector addr = " << &nameList << std::endl;
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
err = pthread_create(&(tid[i]), NULL, &doit, (void **)&loopcnt);
|
||||
|
||||
if (err != 0) {
|
||||
std::cout << "Failed to create thread:[ " << strerror(err) << " ]"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
pthread_join(tid[i], (void **)&b);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
248
test/mttest4.cpp
248
test/mttest4.cpp
@ -1,248 +0,0 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
// #include "common/init/Init.h"
|
||||
|
||||
static char textPad __attribute__((used));
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} UN;
|
||||
typedef UN UN2;
|
||||
typedef struct {
|
||||
int i;
|
||||
float f;
|
||||
char c;
|
||||
} ST;
|
||||
typedef ST ST2;
|
||||
typedef int INT_TYPE;
|
||||
|
||||
/*class Bar {
|
||||
std::string bar;
|
||||
};*/
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
std::vector<std::string> vectorOfStr;
|
||||
std::multimap<int, int> intToStrMultiMap;
|
||||
/* std::vector<std::unordered_map<std::string, std::string>> mapOfStr;
|
||||
bool myb;
|
||||
std::vector<std::pair<std::string, double>> vectorOfPair; */
|
||||
/*UN unionVar;
|
||||
UN2 unionVar2;
|
||||
ST structVar;
|
||||
ST2 structVar2;
|
||||
char t; */
|
||||
char arr[10];
|
||||
int aa;
|
||||
int bb : 1;
|
||||
int : 0;
|
||||
int cc : 5;
|
||||
int dd : 30;
|
||||
|
||||
// Bar bar_arr[5];
|
||||
int ref;
|
||||
};
|
||||
|
||||
Foo myGlobalFoo;
|
||||
// std::unique_ptr<Foo> myGlobalFoo;
|
||||
|
||||
typedef INT_TYPE INT_ARRAY[10];
|
||||
enum ENUM { E_A };
|
||||
|
||||
// pass in the loop counter in the args
|
||||
std::vector<int> doStuff(ENUM e, ENUM *e_p, INT_TYPE int_type,
|
||||
INT_TYPE &int_type_r, INT_TYPE *int_type_p,
|
||||
INT_TYPE **int_type_pp, INT_ARRAY int_array, Foo &foo,
|
||||
std::vector<std::map<std::string, std::string>> &m,
|
||||
std::vector<std::string> &f,
|
||||
std::vector<std::pair<std::string, double>> &p) {
|
||||
std::vector<int> altvect = {1, 3, 5, 7};
|
||||
foo.ref++;
|
||||
myGlobalFoo.vectorOfStr.push_back(std::string("Test String"));
|
||||
|
||||
std::cout << e << e_p << int_type << int_type_r << (uintptr_t)&int_type_p
|
||||
<< (uintptr_t)&int_type_pp << int_array;
|
||||
std::cout << " doStuff entries: " << f.size() << std::endl;
|
||||
std::cout << " addr of f = " << reinterpret_cast<void *>(&f) << std::endl;
|
||||
std::cout << " addr of m = " << reinterpret_cast<void *>(&m) << std::endl;
|
||||
std::cout << " addr of p = " << reinterpret_cast<void *>(&p) << std::endl;
|
||||
std::cout << " addr of myGlobalFoo = "
|
||||
<< reinterpret_cast<void *>(&myGlobalFoo) << std::endl;
|
||||
|
||||
std::vector<int> newvect(altvect);
|
||||
|
||||
std::cout << " addr of newvect = " << reinterpret_cast<void *>(&newvect)
|
||||
<< std::endl;
|
||||
|
||||
return newvect;
|
||||
}
|
||||
|
||||
void doStuff(std::vector<int> &f, int i) {
|
||||
f.push_back(i);
|
||||
std::cout << "Entries in f: " << f.size() << std::endl;
|
||||
}
|
||||
|
||||
void *doit(void *arg) {
|
||||
int *loopcnt = reinterpret_cast<int *>(arg);
|
||||
std::vector<std::string> f;
|
||||
f.reserve(200);
|
||||
std::vector<std::unordered_map<std::string, std::string>> mv;
|
||||
|
||||
std::unordered_map<std::string, std::string> m;
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] = "ba";
|
||||
m["a"] = "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] =
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbaaaaaaaaaaa"] = "bbb";
|
||||
m["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccaaaaaaaa"] = "bbbb";
|
||||
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
mv.push_back(m);
|
||||
|
||||
std::vector<std::pair<std::string, double>> pv;
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdef", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
{
|
||||
std::pair<std::string, double> p(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefghi", 10);
|
||||
pv.push_back(p);
|
||||
}
|
||||
|
||||
for (int i = 0; i < *loopcnt; ++i) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back("abcdefghijklmn");
|
||||
}
|
||||
for (int j = 0; j < 3; j++) {
|
||||
f.push_back(
|
||||
"abcdefghijklmnoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
||||
}
|
||||
Foo foo;
|
||||
|
||||
std::multimap<int, int> mm;
|
||||
|
||||
mm.insert(std::pair<int, int>(0, 0));
|
||||
mm.insert(std::pair<int, int>(1, 10));
|
||||
mm.insert(std::pair<int, int>(2, 20));
|
||||
mm.insert(std::pair<int, int>(3, 30));
|
||||
|
||||
mm.insert(std::pair<int, int>(1, 100));
|
||||
|
||||
foo.intToStrMultiMap = mm;
|
||||
|
||||
/*foo.vectorOfStr = f;
|
||||
foo.mapOfStr = mv;
|
||||
foo.vectorOfPair = pv;*/
|
||||
/*foo.bar_arr[0].bar = "";
|
||||
foo.bar_arr[1].bar = "0123456789";
|
||||
foo.bar_arr[2].bar = "01234567890123456789";
|
||||
foo.bar_arr[3].bar = "0123456789012345678901234567890123456789";
|
||||
foo.bar_arr[4].bar =
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456789";*/
|
||||
|
||||
std::vector<std::map<std::string, std::string>> dummy;
|
||||
INT_TYPE int_type;
|
||||
INT_TYPE *int_type_p;
|
||||
// INT_TYPE arr[10];
|
||||
INT_ARRAY int_arr;
|
||||
ENUM enum_type;
|
||||
std::vector<int> g =
|
||||
doStuff(enum_type, &enum_type, int_type, int_type, int_type_p,
|
||||
&int_type_p, int_arr, foo, dummy, f, pv);
|
||||
doStuff(g, i);
|
||||
|
||||
std::cout << "Number of elems = " << g.size() << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
||||
|
||||
f.clear();
|
||||
}
|
||||
|
||||
pthread_exit(arg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int i = 0;
|
||||
int err;
|
||||
pthread_t tid[2];
|
||||
char *b;
|
||||
|
||||
// facebook::initFacebook(&argc, &argv);
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::cout << "main thread = " << syscall(SYS_gettid) << " pid = " << getpid()
|
||||
<< std::endl;
|
||||
sleep(1);
|
||||
|
||||
std::map<std::string, int> mapOfWords;
|
||||
mapOfWords.insert(std::make_pair("earth", 1));
|
||||
mapOfWords.insert(std::make_pair("moon", 2));
|
||||
mapOfWords["sun"] = 3;
|
||||
|
||||
std::vector<std::string> nameList;
|
||||
nameList.push_back("The quick brown fox");
|
||||
nameList.push_back("jumps over ");
|
||||
nameList.push_back("the ");
|
||||
nameList.push_back("lazy dog ");
|
||||
|
||||
for (auto it = nameList.begin(); it != nameList.end(); it++) {
|
||||
std::cout << "nameList: " << *it << " size: " << it->size() << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords #elements: " << mapOfWords.size() << std::endl;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (auto it = mapOfWords.begin(); it != mapOfWords.end(); ++it) {
|
||||
size += it->first.size();
|
||||
}
|
||||
|
||||
std::cout << "mapOfWords map addr = " << &mapOfWords << std::endl;
|
||||
std::cout << "nameList vector addr = " << &nameList << std::endl;
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
err = pthread_create(&(tid[i]), NULL, &doit, (void **)&loopcnt);
|
||||
|
||||
if (err != 0) {
|
||||
std::cout << "Failed to create thread:[ " << strerror(err) << " ]"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; ++i) {
|
||||
pthread_join(tid[i], (void **)&b);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
typedef struct userDef {
|
||||
int var1;
|
||||
char var2;
|
||||
void *var3;
|
||||
char var4[256];
|
||||
} userDef;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
userDef udefs[10];
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
std::vector<userDef> userDefList;
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
userDefList.push_back(userDef());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (auto udef : userDefList) {
|
||||
std::cout << "userDefList[" << i << "]= " << sizeof(udef) << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "pid = " << getpid()
|
||||
<< " Address of userDefList = " << &userDefList << std::endl;
|
||||
;
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
115
test/vector.cpp
115
test/vector.cpp
@ -1,115 +0,0 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Emp {
|
||||
std::string name;
|
||||
int age;
|
||||
std::vector<Emp> colleagues;
|
||||
|
||||
public:
|
||||
Emp(std::string name1) {
|
||||
name = name1;
|
||||
};
|
||||
void setName(std::string name1) {
|
||||
name = name1;
|
||||
std::cout << "name: " << name << std::endl;
|
||||
};
|
||||
std::string getName(void) {
|
||||
return name;
|
||||
};
|
||||
void setAge(int age) {
|
||||
age = age;
|
||||
};
|
||||
void addColleague(Emp p) {
|
||||
colleagues.emplace(colleagues.begin(), p);
|
||||
};
|
||||
std::vector<Emp> getColleagues(void) {
|
||||
return colleagues;
|
||||
}
|
||||
};
|
||||
|
||||
class Comp {
|
||||
std::string name;
|
||||
std::vector<Comp> companies;
|
||||
|
||||
public:
|
||||
Comp(std::string name1) {
|
||||
name = name1;
|
||||
};
|
||||
std::vector<Comp> getComps(void) {
|
||||
return companies;
|
||||
}
|
||||
};
|
||||
|
||||
void foo(class Emp& me) {
|
||||
std::vector<Emp> colleagues = me.getColleagues();
|
||||
int size = colleagues.size();
|
||||
std::cout << size << std::endl;
|
||||
std::cout << colleagues[4].getName().size() << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <loopcnt> " << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int loopcnt = atoi(argv[1]);
|
||||
|
||||
Emp Jon("Jon Haslam");
|
||||
Emp Mark(std::string("Mark Santaniello"));
|
||||
Emp Kalyan(std::string("Kalyan Saladi"));
|
||||
Emp Banit(std::string("Banit Agrawal"));
|
||||
Emp Harit(std::string("Harit Modi"));
|
||||
Emp Amlan(std::string("Amlan Nayak"));
|
||||
Emp Blaise(std::string("Blaise Sanouillet"));
|
||||
|
||||
Jon.addColleague(Mark);
|
||||
Jon.addColleague(Kalyan);
|
||||
Jon.addColleague(Banit);
|
||||
Jon.addColleague(Harit);
|
||||
Jon.addColleague(Amlan);
|
||||
Jon.addColleague(Blaise);
|
||||
|
||||
std::vector<int> TestVec{10, 20, 30, 20, 10, 40};
|
||||
|
||||
int total = 0;
|
||||
for (auto it = TestVec.begin(); it != TestVec.end(); it++) {
|
||||
total += *it;
|
||||
}
|
||||
|
||||
std::cout << "Total = "
|
||||
<< " " << total << std::endl;
|
||||
|
||||
Comp bus("facebook");
|
||||
std::vector<Comp> m = bus.getComps();
|
||||
std::cout << "Number of Comps: " << m.size() << std::endl;
|
||||
|
||||
std::vector<Emp> mycol = Jon.getColleagues();
|
||||
|
||||
for (auto it = mycol.begin(); it != mycol.end(); ++it) {
|
||||
std::cout << "Colleague: " << it->getName().size()
|
||||
<< " size: " << sizeof(*it) << std::endl;
|
||||
}
|
||||
|
||||
// std::cout << "mycol addr = " << &mycol << std::endl;
|
||||
std::cout << "TestVec addr = " << &TestVec << std::endl;
|
||||
// std::cout << "Number of Colleagues: " << mycol.size() << std::endl;
|
||||
|
||||
std::cout << "pid == " << getpid() << " (hit RETURN to continue)"
|
||||
<< std::endl;
|
||||
|
||||
for (int i = 0; i < loopcnt; i++) {
|
||||
std::cout << "i: " << i << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
foo(Jon);
|
||||
}
|
Loading…
Reference in New Issue
Block a user