mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
perf: get rid of pointless virPerfGetEvent() method
The virPerfGetEvent method pointlessly checks for a NULL parameter and the range of an enum value. The whole point of using an enum is that we can avoid such checks. Just replace calls to virPerfGetEvent, with perf->events[type] array access. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
5fca70ef57
commit
bdcf6e4810
@ -50,7 +50,6 @@ VIR_ENUM_IMPL(virPerfEvent, VIR_PERF_EVENT_LAST,
|
|||||||
"alignment_faults", "emulation_faults");
|
"alignment_faults", "emulation_faults");
|
||||||
|
|
||||||
struct virPerfEvent {
|
struct virPerfEvent {
|
||||||
int type;
|
|
||||||
int fd;
|
int fd;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
union {
|
union {
|
||||||
@ -206,23 +205,6 @@ virPerfRdtAttrInit(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virPerfEventPtr
|
|
||||||
virPerfGetEvent(virPerfPtr perf,
|
|
||||||
virPerfEventType type)
|
|
||||||
{
|
|
||||||
if (!perf)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (type >= VIR_PERF_EVENT_LAST) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Event '%d' is not supported"),
|
|
||||||
type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return perf->events + type;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virPerfEventEnable(virPerfPtr perf,
|
virPerfEventEnable(virPerfPtr perf,
|
||||||
virPerfEventType type,
|
virPerfEventType type,
|
||||||
@ -230,12 +212,9 @@ virPerfEventEnable(virPerfPtr perf,
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
struct perf_event_attr attr;
|
struct perf_event_attr attr;
|
||||||
virPerfEventPtr event = virPerfGetEvent(perf, type);
|
virPerfEventPtr event = &(perf->events[type]);
|
||||||
virPerfEventAttrPtr event_attr = &attrs[type];
|
virPerfEventAttrPtr event_attr = &attrs[type];
|
||||||
|
|
||||||
if (!event)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (event->enabled)
|
if (event->enabled)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -274,14 +253,14 @@ virPerfEventEnable(virPerfPtr perf,
|
|||||||
if (event->fd < 0) {
|
if (event->fd < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("unable to open host cpu perf event for %s"),
|
_("unable to open host cpu perf event for %s"),
|
||||||
virPerfEventTypeToString(event->type));
|
virPerfEventTypeToString(type));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(event->fd, PERF_EVENT_IOC_ENABLE) < 0) {
|
if (ioctl(event->fd, PERF_EVENT_IOC_ENABLE) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("unable to enable host cpu perf event for %s"),
|
_("unable to enable host cpu perf event for %s"),
|
||||||
virPerfEventTypeToString(event->type));
|
virPerfEventTypeToString(type));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,9 +277,7 @@ int
|
|||||||
virPerfEventDisable(virPerfPtr perf,
|
virPerfEventDisable(virPerfPtr perf,
|
||||||
virPerfEventType type)
|
virPerfEventType type)
|
||||||
{
|
{
|
||||||
virPerfEventPtr event = virPerfGetEvent(perf, type);
|
virPerfEventPtr event = &(perf->events[type]);
|
||||||
if (event == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!event->enabled)
|
if (!event->enabled)
|
||||||
return 0;
|
return 0;
|
||||||
@ -308,7 +285,7 @@ virPerfEventDisable(virPerfPtr perf,
|
|||||||
if (ioctl(event->fd, PERF_EVENT_IOC_DISABLE) < 0) {
|
if (ioctl(event->fd, PERF_EVENT_IOC_DISABLE) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("unable to disable host cpu perf event for %s"),
|
_("unable to disable host cpu perf event for %s"),
|
||||||
virPerfEventTypeToString(event->type));
|
virPerfEventTypeToString(type));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,11 +297,7 @@ virPerfEventDisable(virPerfPtr perf,
|
|||||||
bool virPerfEventIsEnabled(virPerfPtr perf,
|
bool virPerfEventIsEnabled(virPerfPtr perf,
|
||||||
virPerfEventType type)
|
virPerfEventType type)
|
||||||
{
|
{
|
||||||
virPerfEventPtr event = virPerfGetEvent(perf, type);
|
return perf->events[type].enabled;
|
||||||
if (event == NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return event->enabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -332,8 +305,8 @@ virPerfReadEvent(virPerfPtr perf,
|
|||||||
virPerfEventType type,
|
virPerfEventType type,
|
||||||
uint64_t *value)
|
uint64_t *value)
|
||||||
{
|
{
|
||||||
virPerfEventPtr event = virPerfGetEvent(perf, type);
|
virPerfEventPtr event = &perf->events[type];
|
||||||
if (event == NULL || !event->enabled)
|
if (!event->enabled)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (saferead(event->fd, value, sizeof(uint64_t)) < 0) {
|
if (saferead(event->fd, value, sizeof(uint64_t)) < 0) {
|
||||||
@ -404,7 +377,6 @@ virPerfNew(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
|
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
|
||||||
perf->events[i].type = i;
|
|
||||||
perf->events[i].fd = -1;
|
perf->events[i].fd = -1;
|
||||||
perf->events[i].enabled = false;
|
perf->events[i].enabled = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user