| 539 | // ============= export to files ============== |
| 540 | |
| 541 | std::string read_command_name() { |
| 542 | std::ifstream fin("/proc/self/stat"); |
| 543 | if (!fin.is_open()) { |
| 544 | return std::string(); |
| 545 | } |
| 546 | int pid = 0; |
| 547 | std::string command_name; |
| 548 | fin >> pid >> command_name; |
| 549 | if (!fin.good()) { |
| 550 | return std::string(); |
| 551 | } |
| 552 | // Although the man page says the command name is in parenthesis, for |
| 553 | // safety we normalize the name. |
| 554 | std::string s; |
| 555 | if (command_name.size() >= 2UL && command_name[0] == '(' && |
| 556 | butil::back_char(command_name) == ')') { |
| 557 | // remove parenthesis. |
| 558 | to_underscored_name(&s, |
| 559 | butil::StringPiece(command_name.data() + 1, |
| 560 | command_name.size() - 2UL)); |
| 561 | } else { |
| 562 | to_underscored_name(&s, command_name); |
| 563 | } |
| 564 | return s; |
| 565 | } |
| 566 | |
| 567 | class FileDumper : public Dumper { |
| 568 | public: |
no test coverage detected