Skip to content

Commit

Permalink
Capturing command line and arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Feb 4, 2019
1 parent 9e4cc1c commit 2423438
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/apex/apex_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ namespace apex
std::cout << #name << " : " << options.member_variable() << std::endl;
FOREACH_APEX_STRING_OPTION(apex_macro)
#undef apex_macro
std::unique_ptr<std::string> tmpstr = proc_data_reader::get_command_line();
std::string tmpstr(proc_data_reader::get_command_line());
if (tmpstr.length() > 0) {
std::cout << tmpstr << std::endl;
std::cout << "Command line: " << tmpstr << std::endl;
}
return;
}
Expand Down
22 changes: 10 additions & 12 deletions src/apex/proc_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "apex_api.hpp"
#include "apex.hpp"
#include <sstream>
#include <fstream>
#include <atomic>
#include <unordered_set>
#include <string>
Expand Down Expand Up @@ -694,21 +695,18 @@ double msr_current_power_high(void) {
}
#endif

std::unique_ptr<std::string> proc_data_reader::get_command_line(void) {
std::string proc_data_reader::get_command_line(void) {
std::string line;
std::fstream myfile ("/proc/self/cmdline");
std::stringstream ss;
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
ss << line << '\n';
}
myfile.close();
std::fstream myfile("/proc/self/cmdline", ios_base::in);
if (myfile.is_open()) {
getline (myfile,line);
myfile.close();
} else {
// it wasn't there, so return nothing.
// it wasn't there, so return nothing.
}
return std::move(ss.str());
return line;
}

} // namespace

#endif // APEX_HAVE_PROC
2 changes: 1 addition & 1 deletion src/apex/proc_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class proc_data_reader {
stop_reading();
delete worker_thread;
}
static std::unique_ptr<std::string> get_command_line(void);
static std::string get_command_line(void);
};

class ProcData {
Expand Down

0 comments on commit 2423438

Please sign in to comment.