Skip to content

Commit 80503ba

Browse files
Merge pull request #4 from Durganshu/develop
Debugging fixes and improved stability
2 parents a2015d3 + 3e07634 commit 80503ba

File tree

11 files changed

+62
-77
lines changed

11 files changed

+62
-77
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,19 @@ The default installation of `mitos` will be configured for Intel based Precise E
151151

152152
## Saving the virtual address
153153

154-
The source code of the executable must save the virtual addess offset when the executable starts runnnig. This can be done by including the [virtual_address_writer.h](src/virtual_address_writer.h) and calling the function [save_virtual_address_offset("virt_address.txt")](src/virtual_address_writer.h#L18).
154+
The source code of the executable must save the virtual addess offset when the executable starts runnnig. This can be done by including the [virtual_address_writer.h](src/virtual_address_writer.h) and calling the function [save_virtual_address_offset("/tmp/mitos_virt_address.txt")](src/virtual_address_writer.h#L18).
155155

156156
See [matmul.cpp](examples/matmul.cpp) for reference.
157157

158-
This saves the virtual address offset to `/tmp/virt_address.txt`. Dyninst will access this file and attribute the source code information when the samples are saved.
158+
This saves the virtual address offset to `/tmp/mitos_virt_address.txt`. Dyninst will access this file and attribute the source code information when the samples are saved.
159+
160+
When running the application with `mitosrun`, another location can also be specified. When doing this, use `-l` option with the `mitosrun` to specify the location of the file.
161+
162+
For instance, if the application saves virtual address by calling `save_virtual_address_offset("/myPath/mitos_virt_address.txt")`, `mitosrun` can be run as:
163+
164+
```shell
165+
./mitosrun -l /myPath/mitos_virt_address.txt ./myApplication
166+
```
159167

160168
# Authors
161169

examples/api_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void matmul(int N, double *a, double *b, double *c)
6565

6666
int main(int argc, char **argv)
6767
{
68-
save_virtual_address_offset("virt_address.txt");
68+
save_virtual_address_offset("/tmp/mitos_virt_address.txt");
6969
int N = (argc == 2) ? atoi(argv[1]) : 1024;
7070

7171
double *a,*b,*c;
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
8282
matmul(N,a,b,c);
8383
Mitos_end_sampler();
8484
std::set<std::string> src_files;
85-
Mitos_add_offsets("", &mout);
85+
Mitos_add_offsets("/tmp/mitos_virt_address.txt", &mout);
8686
if(Mitos_openFile(argv[0], &mout))
8787
{
8888
std::cerr << "Error opening binary file!" << std::endl;

examples/matmul.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void matmul(int N, double *a, double *b, double *c)
5252
int main(int argc, char **argv)
5353
{
5454
int N = (argc == 2) ? atoi(argv[1]) : 1024;
55-
save_virtual_address_offset("virt_address.txt");
55+
save_virtual_address_offset("/tmp/mitos_virt_address.txt");
5656
double *a,*b,*c;
5757
init_matrices(N,&a,&b,&c);
5858
matmul(N,a,b,c);

examples/omp_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void do_something_single_thread() {
1919
}
2020

2121
int main() {
22-
save_virtual_address_offset("virt_address.txt");
22+
save_virtual_address_offset("/tmp/mitos_virt_address.txt");
2323
do_something_single_thread();
2424
#pragma omp parallel default(none) num_threads(8)
2525
{

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ add_library(mitoshooks SHARED ${MITOSHOOKS_SRC_FILES} ${MITOS_SRC_FILES})
1414

1515
# Binaries
1616
add_executable(mitosrun mitosrun.cpp)
17-
add_executable(demo_post_process demo.cpp)
17+
add_executable(mitos_post_process mitos_post_process.cpp)
1818

1919
# Linkage
2020
target_link_libraries(mitos mitoshooks numa hwloc ${CMAKE_THREAD_LIBS_INIT} stdc++fs)
2121
target_link_libraries(mitosrun mitos)
22-
target_link_libraries(demo_post_process mitos common)
22+
target_link_libraries(mitos_post_process mitos common)
2323
target_link_libraries(mitoshooks dl)
2424

2525
if(MPI_FOUND)
@@ -37,7 +37,7 @@ install(FILES ${MITOS_HDR_PUBLIC}
3737
install(TARGETS mitosrun
3838
EXPORT mitos-targets
3939
DESTINATION bin)
40-
install(TARGETS demo_post_process
40+
install(TARGETS mitos_post_process
4141
EXPORT mitos-targets
4242
DESTINATION bin)
4343
install(TARGETS mitos

src/Mitos.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ struct mitos_output
138138
char *dname_srcdir;
139139
char *dname_hwdatadir;
140140

141-
std::string dname_srcdir_orig;
142-
143141
char *fname_raw;
144142
char *fname_processed;
145143

File renamed without changes.

src/mitoshooks.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ long ts_output = 0;
6262

6363
void sample_handler(perf_event_sample *sample, void *args)
6464
{
65-
LOG_MEDIUM("mitoshooks.cpp: sample_handler(), MPI handler sample: cpu= " << sample->cpu << " tid= " << sample->tid);
65+
LOG_HIGH("mitoshooks.cpp: sample_handler(), MPI handler sample: cpu= " << sample->cpu << " tid= " << sample->tid);
6666
Mitos_write_sample(sample, &mout);
6767
}
6868

@@ -77,12 +77,14 @@ int MPI_Init(int *argc, char ***argv)
7777
MPI_Bcast(&ts_output, 1, MPI_LONG, 0, MPI_COMM_WORLD);
7878
// send timestamp from rank 0 to all others to synchronize folder prefix
7979

80-
char rank_prefix[48];
81-
sprintf(rank_prefix, "%ld_rank_%d_", ts_output, mpi_rank);
80+
char rank_prefix[54];
81+
sprintf(rank_prefix, "mitos_%ld_rank_%d_", ts_output, mpi_rank);
8282

83-
virt_address = new char[strlen(rank_prefix) + 1];
84-
strcpy(virt_address, rank_prefix);
85-
save_virtual_address_offset(std::string(rank_prefix) + std::string("virt_address.txt"));
83+
virt_address = new char[(strlen(rank_prefix) + strlen("/tmp/") + strlen("virt_address.txt") + 1)];
84+
strcpy(virt_address, "/tmp/");
85+
strcat(virt_address, rank_prefix);
86+
strcat(virt_address, "virt_address.txt");
87+
save_virtual_address_offset(std::string(virt_address));
8688
// Take user inputs
8789
int sampling_period = DEFAULT_PERIOD;
8890
int latency_threshold = DEFAULT_THRESH;
@@ -112,8 +114,8 @@ int MPI_Init_thread(int *argc, char ***argv, int required, int *provided)
112114
int mpi_rank;
113115
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
114116

115-
char rank_prefix[32];
116-
sprintf(rank_prefix, "rank_%d", mpi_rank);
117+
char rank_prefix[38];
118+
sprintf(rank_prefix, "mitos_rank_%d", mpi_rank);
117119

118120
// Take user inputs
119121
int sampling_period = DEFAULT_PERIOD;
@@ -143,11 +145,11 @@ int MPI_Finalize()
143145
Mitos_add_offsets(virt_address, &mout);
144146
// merge files
145147
if (mpi_rank == 0) {
146-
int ret_val = Mitos_merge_files(std::to_string(ts_output) + "_rank_", std::to_string(ts_output) + "_rank_0");
148+
int ret_val = Mitos_merge_files(std::string("mitos_") + std::to_string(ts_output) + "_rank_", std::string("mitos_") + std::to_string(ts_output) + "_rank_0");
147149
Mitos_openFile("/proc/self/exe", &mout);
148150
std::set<std::string> src_files;
149151
mitos_output result_mout;
150-
std::string result_dir = std::to_string(ts_output) + "_rank_result";
152+
std::string result_dir = "mitos_" + std::to_string(ts_output) + "_rank_result";
151153
Mitos_set_result_mout(&result_mout, result_dir.c_str());
152154
Mitos_post_process("/proc/self/exe", &result_mout, src_files);
153155
Mitos_copy_sources(result_dir, src_files);
@@ -164,7 +166,7 @@ int MPI_Finalize()
164166

165167
void sample_handler_omp(perf_event_sample *sample, void *args)
166168
{
167-
LOG_MEDIUM("mitoshooks.cpp: sample_handler_omp(), MPI handler sample: cpu= " << sample->cpu << " tid= " << sample->tid);
169+
LOG_HIGH("mitoshooks.cpp: sample_handler_omp(), MPI handler sample: cpu= " << sample->cpu << " tid= " << sample->tid);
168170
Mitos_write_sample(sample, &mout);
169171
}
170172

@@ -203,23 +205,25 @@ static void on_ompt_callback_thread_begin(ompt_thread_t thread_type,
203205
LOG_MEDIUM("mitoshooks.cpp: on_ompt_callback_thread_begin(), Start Thread OMP:= " << getpid()
204206
<< " tid= " << tid << " omp_tid= " << tid_omp << " cpu_id= " << cpu_num);
205207
#endif
206-
char rank_prefix[48];
207-
sprintf(rank_prefix, "%ld_openmp_distr_mon_%d_", ts_output_prefix_omp, tid);
208+
char rank_prefix[54];
209+
sprintf(rank_prefix, "mitos_%ld_openmp_distr_mon_%d_", ts_output_prefix_omp, tid);
208210
Mitos_create_output(&mout, rank_prefix);
209211
#if CURRENT_VERBOSITY >= VERBOSE_MEDIUM
210212
pid_t curpid = getpid();
211213
LOG_MEDIUM("mitoshooks.cpp: on_ompt_callback_thread_begin(), Curpid:= " << curpid);
212214
#endif
213-
virt_address = new char[strlen(rank_prefix) + 1];
214-
strcpy(virt_address, rank_prefix);
215-
save_virtual_address_offset(std::string(rank_prefix) + std::string("virt_address.txt"));
215+
virt_address = new char[(strlen(rank_prefix) + strlen("/tmp/") + strlen("virt_address.txt") + 1)];
216+
strcpy(virt_address, "/tmp/");
217+
strcat(virt_address, rank_prefix);
218+
strcat(virt_address, "virt_address.txt");
219+
save_virtual_address_offset(std::string(virt_address));
216220
// Take user inputs
217221
int sampling_period = DEFAULT_PERIOD;
218222
int latency_threshold = DEFAULT_THRESH;
219223
Mitos_get_environment_variables(sampling_period, latency_threshold);
220224

221225
Mitos_pre_process(&mout);
222-
Mitos_set_pid(getpid());
226+
Mitos_set_pid(tid);
223227

224228
Mitos_set_handler_fn(&sample_handler_omp,NULL);
225229
Mitos_set_sample_latency_threshold(latency_threshold);
@@ -269,7 +273,7 @@ void ompt_finalize(ompt_data_t *tool_data) {
269273
omp_get_wtime() - *(double *) (tool_data->ptr));
270274

271275
printf("End Sampler...\n");
272-
Mitos_merge_files(std::to_string(ts_output_prefix_omp) + "_openmp_distr_mon", std::to_string(ts_output_prefix_omp) + "_openmp_distr_mon_" + std::to_string(tid_omp_first));
276+
Mitos_merge_files("mitos_" + std::to_string(ts_output_prefix_omp) + "_openmp_distr_mon", "mitos_" + std::to_string(ts_output_prefix_omp) + "_openmp_distr_mon_" + std::to_string(tid_omp_first));
273277
{
274278
auto bin_name = [](pid_t pid) -> std::string {
275279
char buffer[1024];
@@ -291,7 +295,7 @@ void ompt_finalize(ompt_data_t *tool_data) {
291295
};
292296
std::cout << "\n*******************************************************************\n\n";
293297
std::cout << "Samples collected and written as raw data. Run the following command for post-processing the samples: \n ";
294-
std::cout << "./demo_post_process " <<bin_name(getpid()) << " " + std::to_string(ts_output_prefix_omp) + "_openmp_distr_monresult\n";
298+
std::cout << "./mitos_post_process " <<bin_name(getpid()) << " mitos_" + std::to_string(ts_output_prefix_omp) + "_openmp_distr_monresult\n";
295299
std::cout << "\n*******************************************************************\n\n";
296300
}
297301

src/mitosoutput.cpp

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,6 @@ int Mitos_create_output(mitos_output *mout, const char *prefix_name)
9898
return 1;
9999
}
100100

101-
//copy over source code to mitos output folder
102-
if (!mout->dname_srcdir_orig.empty())
103-
{
104-
if(!fs::exists(mout->dname_srcdir_orig))
105-
{
106-
std::cerr << "Mitos: Source code path " << mout->dname_srcdir_orig << "does not exist!\n";
107-
return 1;
108-
}
109-
std::error_code ec;
110-
fs::copy(mout->dname_srcdir_orig, mout->dname_srcdir, ec);
111-
if(ec)
112-
{
113-
std::cerr << "Mitos: Source code path " << mout->dname_srcdir_orig << "was not copied. Error " << ec.value() << ".\n";
114-
return 1;
115-
}
116-
}
117101

118102
mout->ok = true;
119103

@@ -140,14 +124,14 @@ int Mitos_pre_process(mitos_output *mout)
140124
return 1;
141125
}
142126

143-
std::string fname_lshw = std::string(mout->dname_hwdatadir) + "/lshw.xml";
144-
std::string lshw_cmd = "lshw -c memory -xml > " + fname_lshw;
145-
err = system(lshw_cmd.c_str());
146-
if(err)
147-
{
148-
std::cerr << "Mitos: Failed to create hardware topology file!\n";
149-
return 1;
150-
}
127+
// std::string fname_lshw = std::string(mout->dname_hwdatadir) + "/lshw.xml";
128+
// std::string lshw_cmd = "lshw -c memory -xml > " + fname_lshw;
129+
// err = system(lshw_cmd.c_str());
130+
// if(err)
131+
// {
132+
// std::cerr << "Mitos: Failed to create hardware topology file!\n";
133+
// return 1;
134+
// }
151135

152136
return 0;
153137
}
@@ -326,7 +310,7 @@ int Mitos_write_sample(perf_event_sample *sample, mitos_output *mout)
326310
int Mitos_add_offsets(const char * virt_address, mitos_output *mout){
327311

328312
// Read the virtual address
329-
std::string loc = std::string("/tmp/") + std::string(virt_address) + std::string("virt_address.txt");
313+
std::string loc = virt_address;
330314
std::ifstream foffset(loc);
331315
long long offsetAddr = 0;
332316
std::string str_offset;
@@ -441,6 +425,7 @@ std::ofstream fproc(mout->fname_processed);
441425
return 1;
442426
}
443427
return 0;
428+
#endif // USE_DYNINST
444429
}
445430

446431
int Mitos_post_process(const char *bin_name, mitos_output *mout, std::set<std::string>& src_files)
@@ -466,7 +451,7 @@ int Mitos_post_process(const char *bin_name, mitos_output *mout, std::set<std::s
466451
Dyninst::Offset ip;
467452
std::string line, ip_str;
468453
int tmp_line = 0;
469-
LOG_MEDIUM("mitosoutput.cpp: Mitos_post_process(), reading raw samples...");
454+
LOG_HIGH("mitosoutput.cpp: Mitos_post_process(), reading raw samples...");
470455

471456
while(std::getline(fraw, line).good())
472457
{
@@ -493,14 +478,6 @@ int Mitos_post_process(const char *bin_name, mitos_output *mout, std::set<std::s
493478
if(sym_success)
494479
{
495480
source = (string)stats[0]->getFile();
496-
if (!mout->dname_srcdir_orig.empty())
497-
{
498-
std::size_t pos = source.find(mout->dname_srcdir_orig);
499-
if(pos == 0){
500-
source = source.substr(mout->dname_srcdir_orig.length() + (mout->dname_srcdir_orig.back() == '/' ? 0 : 1)); //to remove slash if there is none in the string
501-
}
502-
503-
}
504481
line_num << stats[0]->getLine();
505482
}
506483
if(!source.empty()){
@@ -549,8 +526,6 @@ int Mitos_post_process(const char *bin_name, mitos_output *mout, std::set<std::s
549526
return 1;
550527
}
551528

552-
#endif // USE_DYNINST
553-
554529
return 0;
555530
}
556531

src/mitosrun.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ uint64_t thresh;
2020
mitos_output mout;
2121
std::vector<perf_event_sample> samples;
2222
pid_t child_pid;
23-
23+
static std::string address_file;
2424
/* Helper function for writing samples.*/
2525
void dump_samples()
2626
{
@@ -54,7 +54,7 @@ void usage(char **argv)
5454
std::cerr << " -b sample buffer size (default 4096)" << std::endl;
5555
std::cerr << " -p sample period (default 4000)" << std::endl;
5656
std::cerr << " -t sample latency threshold (default 10)" << std::endl;
57-
std::cerr << " -s top folder of source code to copy" << std::endl;
57+
std::cerr << " -l location of virtual address file (default /tmp/mitos_virt_address.txt)" << std::endl;
5858
std::cerr << " <cmd>: command to sample on (required)" << std::endl;
5959
std::cerr << " [args]: command arguments" << std::endl;
6060
}
@@ -65,7 +65,7 @@ void set_defaults()
6565
bufsz = DEFAULT_BUFSZ;
6666
period = DEFAULT_PERIOD;
6767
thresh = DEFAULT_THRESH;
68-
mout.dname_srcdir_orig = "";
68+
address_file = "/tmp/mitos_virt_address.txt";
6969
}
7070

7171
/* Parses command line arguments.*/
@@ -74,7 +74,7 @@ int parse_args(int argc, char **argv)
7474
set_defaults();
7575

7676
int c;
77-
while((c=getopt(argc, argv, "b:p:t:s:")) != -1)
77+
while((c=getopt(argc, argv, "b:p:t:l:")) != -1)
7878
{
7979
switch(c)
8080
{
@@ -87,9 +87,9 @@ int parse_args(int argc, char **argv)
8787
case 't':
8888
thresh = atoi(optarg);
8989
break;
90-
case 's':
91-
mout.dname_srcdir_orig = optarg;
92-
break;
90+
case 'l':
91+
address_file = optarg;
92+
break;
9393
case '?':
9494
usage(argv);
9595
return 1;
@@ -198,7 +198,7 @@ int main(int argc, char **argv)
198198
std::cout << "Command completed! Processing samples..." << "\n";
199199
std::cout << "Bin Name" << argv[cmdarg] << "\n";
200200
std::set<std::string> src_files;
201-
Mitos_add_offsets("", &mout);
201+
Mitos_add_offsets(address_file.c_str(), &mout);
202202
if(Mitos_openFile(argv[cmdarg], &mout))
203203
{
204204
std::cerr << "Error opening binary file!" << std::endl;
@@ -208,6 +208,7 @@ int main(int argc, char **argv)
208208
std::cerr << "Error post processing!" << std::endl;
209209
return 1;
210210
}
211+
Mitos_copy_sources(mout.dname_topdir, src_files);
211212
std::cout << "Done!\n";
212213
}
213214

0 commit comments

Comments
 (0)