summaryrefslogtreecommitdiffstats
path: root/trace
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-09-05 09:59:31 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-09-05 10:44:31 +0200
commit07829ca0b4b3bee966b3aa9121da1dd37a8d8c4a (patch)
treed1d6a33665f1ee9dbf4d75bd6e00b03159fff14c /trace
parentrecord: Clean up metadata (diff)
downloadrtems-tools-07829ca0b4b3bee966b3aa9121da1dd37a8d8c4a.tar.bz2
record: Use C++ header files and namespace std
Update #3665.
Diffstat (limited to 'trace')
-rw-r--r--trace/record/client.h4
-rw-r--r--trace/record/record-client-base.cc16
-rw-r--r--trace/record/record-main-lttng.cc35
3 files changed, 28 insertions, 27 deletions
diff --git a/trace/record/client.h b/trace/record/client.h
index 274db20..a865a18 100644
--- a/trace/record/client.h
+++ b/trace/record/client.h
@@ -31,9 +31,9 @@
#include <rtems/recordclient.h>
#include <rtems/recorddata.h>
-#include <errno.h>
#include <sys/types.h>
+#include <cerrno>
#include <csignal>
#include <cstring>
#include <iostream>
@@ -43,7 +43,7 @@
class ErrnoException : public std::runtime_error {
public:
ErrnoException(std::string msg)
- : std::runtime_error(msg + ": " + strerror(errno)) {
+ : std::runtime_error(msg + ": " + std::strerror(errno)) {
// Nothing to do
}
};
diff --git a/trace/record/record-client-base.cc b/trace/record/record-client-base.cc
index 607a250..01ed803 100644
--- a/trace/record/record-client-base.cc
+++ b/trace/record/record-client-base.cc
@@ -28,27 +28,27 @@
#include "client.h"
#include <arpa/inet.h>
-#include <assert.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <cassert>
#include <cstring>
static ssize_t ReadFile(int fd, void* buf, size_t n) {
- return read(fd, buf, n);
+ return ::read(fd, buf, n);
}
static ssize_t ReadSocket(int fd, void* buf, size_t n) {
- return recv(fd, buf, n, 0);
+ return ::recv(fd, buf, n, 0);
}
void FileDescriptor::Open(const char* file) {
assert(fd_ == -1);
- fd_ = open(file, O_RDONLY);
+ fd_ = ::open(file, O_RDONLY);
if (fd_ < 0) {
throw ErrnoException(std::string("cannot open file '") + file + "'");
}
@@ -59,18 +59,18 @@ void FileDescriptor::Open(const char* file) {
void FileDescriptor::Connect(const char* host, uint16_t port) {
assert(fd_ == -1);
- fd_ = socket(PF_INET, SOCK_STREAM, 0);
+ fd_ = ::socket(PF_INET, SOCK_STREAM, 0);
if (fd_ < 0) {
throw ErrnoException("cannot open socket");
}
struct sockaddr_in in_addr;
- memset(&in_addr, 0, sizeof(in_addr));
+ std::memset(&in_addr, 0, sizeof(in_addr));
in_addr.sin_family = AF_INET;
in_addr.sin_port = htons(port);
in_addr.sin_addr.s_addr = inet_addr(host);
- int rv = connect(fd_, (struct sockaddr*)&in_addr, sizeof(in_addr));
+ int rv = ::connect(fd_, (struct sockaddr*)&in_addr, sizeof(in_addr));
if (rv != 0) {
throw ErrnoException(std::string("cannot connect to ") + host + " port " +
std::to_string(port));
@@ -81,7 +81,7 @@ void FileDescriptor::Connect(const char* host, uint16_t port) {
void FileDescriptor::Destroy() {
if (fd_ != -1) {
- int rv = close(fd_);
+ int rv = ::close(fd_);
if (rv != 0) {
std::cerr << "close failed: " << strerror(errno) << std::endl;
}
diff --git a/trace/record/record-main-lttng.cc b/trace/record/record-main-lttng.cc
index 25c3c78..d2d2f1c 100644
--- a/trace/record/record-main-lttng.cc
+++ b/trace/record/record-main-lttng.cc
@@ -28,9 +28,10 @@
#include "client.h"
-#include <assert.h>
#include <getopt.h>
+#include <cassert>
+#include <cstdio>
#include <cstring>
#include <iostream>
@@ -132,8 +133,8 @@ class LTTNGClient : public Client {
LTTNGClient() {
Initialize(LTTNGClient::HandlerCaller);
- memset(&pkt_ctx_, 0, sizeof(pkt_ctx_));
- memcpy(pkt_ctx_.header.uuid, kUUID, sizeof(pkt_ctx_.header.uuid));
+ std::memset(&pkt_ctx_, 0, sizeof(pkt_ctx_));
+ std::memcpy(pkt_ctx_.header.uuid, kUUID, sizeof(pkt_ctx_.header.uuid));
pkt_ctx_.header.ctf_magic = CTF_MAGIC;
for (size_t i = 0; i < RTEMS_RECORD_CLIENT_MAXIMUM_CPU_COUNT; ++i) {
@@ -234,7 +235,7 @@ void LTTNGClient::CopyThreadName(const ClientItem& item,
name = kEmptyThreadName;
}
- memcpy(dst, name, THREAD_NAME_SIZE);
+ std::memcpy(dst, name, THREAD_NAME_SIZE);
if (IsIdleTaskByAPIIndex(api_index)) {
/*
@@ -258,7 +259,7 @@ void LTTNGClient::WriteSchedSwitch(PerCPUContext* pcpu,
ss.next_tid = IsIdleTaskByAPIIndex(api_index) ? 0 : item.data;
CopyThreadName(item, api_index, ss.next_comm);
- fwrite(&ss, sizeof(ss), 1, pcpu->event_stream);
+ std::fwrite(&ss, sizeof(ss), 1, pcpu->event_stream);
}
void LTTNGClient::WriteIRQHandlerEntry(PerCPUContext* pcpu,
@@ -268,7 +269,7 @@ void LTTNGClient::WriteIRQHandlerEntry(PerCPUContext* pcpu,
EventIRQHandlerEntry& ih = pcpu->irq_handler_entry;
ih.header.ns = item.ns;
ih.irq = static_cast<int32_t>(item.data);
- fwrite(&ih, sizeof(ih), 1, pcpu->event_stream);
+ std::fwrite(&ih, sizeof(ih), 1, pcpu->event_stream);
}
void LTTNGClient::WriteIRQHandlerExit(PerCPUContext* pcpu,
@@ -278,7 +279,7 @@ void LTTNGClient::WriteIRQHandlerExit(PerCPUContext* pcpu,
EventIRQHandlerExit& ih = pcpu->irq_handler_exit;
ih.header.ns = item.ns;
ih.irq = static_cast<int32_t>(item.data);
- fwrite(&ih, sizeof(ih), 1, pcpu->event_stream);
+ std::fwrite(&ih, sizeof(ih), 1, pcpu->event_stream);
}
void LTTNGClient::AddThreadName(PerCPUContext* pcpu, const ClientItem& item) {
@@ -379,19 +380,19 @@ void LTTNGClient::OpenStreamFiles(uint64_t data) {
for (size_t i = 0; i < cpu_count_; ++i) {
std::string filename("stream_");
filename += std::to_string(i);
- FILE* f = fopen(filename.c_str(), "wb");
+ FILE* f = std::fopen(filename.c_str(), "wb");
if (f == NULL) {
throw ErrnoException("cannot create file '" + filename + "'");
}
per_cpu_[i].event_stream = f;
- fwrite(&pkt_ctx_, sizeof(pkt_ctx_), 1, f);
+ std::fwrite(&pkt_ctx_, sizeof(pkt_ctx_), 1, f);
}
}
void LTTNGClient::CloseStreamFiles() {
for (size_t i = 0; i < cpu_count_; ++i) {
PerCPUContext* pcpu = &per_cpu_[i];
- fseek(pcpu->event_stream, 0, SEEK_SET);
+ std::fseek(pcpu->event_stream, 0, SEEK_SET);
pkt_ctx_.header.stream_instance_id = i;
pkt_ctx_.timestamp_begin = pcpu->timestamp_begin;
@@ -400,8 +401,8 @@ void LTTNGClient::CloseStreamFiles() {
pkt_ctx_.packet_size = pkt_ctx_.content_size;
pkt_ctx_.cpu_id = i;
- fwrite(&pkt_ctx_, sizeof(pkt_ctx_), 1, pcpu->event_stream);
- fclose(pcpu->event_stream);
+ std::fwrite(&pkt_ctx_, sizeof(pkt_ctx_), 1, pcpu->event_stream);
+ std::fclose(pcpu->event_stream);
}
}
@@ -527,19 +528,19 @@ static const char kMetadata[] =
"};\n";
static void GenerateMetadata() {
- FILE* f = fopen("metadata", "w");
+ FILE* f = std::fopen("metadata", "w");
if (f == NULL) {
throw ErrnoException("cannot create file 'metadata'");
}
- fwrite(kMetadata, sizeof(kMetadata) - 1, 1, f);
- fclose(f);
+ std::fwrite(kMetadata, sizeof(kMetadata) - 1, 1, f);
+ std::fclose(f);
}
static LTTNGClient client;
static void SignalHandler(int s) {
client.RequestStop();
- signal(s, SIG_DFL);
+ std::signal(s, SIG_DFL);
}
static const struct option kLongOpts[] = {{"help", 0, NULL, 'h'},
@@ -615,7 +616,7 @@ int main(int argc, char** argv) {
client.Connect(host, port);
}
- signal(SIGINT, SignalHandler);
+ std::signal(SIGINT, SignalHandler);
client.Run();
client.Destroy();
} catch (std::exception& e) {