Skip to content

Commit

Permalink
add userAttribute: key=latency (KindlingProject#286)
Browse files Browse the repository at this point in the history
Signed-off-by: jundizhou <[email protected]>
  • Loading branch information
jundizhou authored Jul 1, 2022
1 parent 01771fe commit 8a1c0bf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
59 changes: 59 additions & 0 deletions probe/src/cgo/kindling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ int getEvent(void **pp_kindling_event)
}

uint16_t userAttNumber = 0;
uint16_t source = get_kindling_source(ev->get_type());
if(source == SYSCALL_EXIT) {
strcpy(p_kindling_event->userAttributes[userAttNumber].key, "latency");
memcpy(p_kindling_event->userAttributes[userAttNumber].value, to_string(threadInfo->m_latency).data(), 8);
p_kindling_event->userAttributes[userAttNumber].valueType = UINT64;
p_kindling_event->userAttributes[userAttNumber].len = 8;
}
userAttNumber++;
switch(ev->get_type())
{
case PPME_TCP_RCV_ESTABLISHED_E:
Expand Down Expand Up @@ -506,3 +514,54 @@ uint16_t get_kindling_category(sinsp_evt *sEvt)
return CAT_OTHER;
}
}

uint16_t get_kindling_source(uint16_t etype) {
if (PPME_IS_ENTER(etype)) {
switch (etype) {
case PPME_PROCEXIT_E:
case PPME_SCHEDSWITCH_6_E:
case PPME_SYSDIGEVENT_E:
case PPME_CONTAINER_E:
case PPME_PROCINFO_E:
case PPME_SCHEDSWITCH_1_E:
case PPME_DROP_E:
case PPME_PROCEXIT_1_E:
case PPME_CPU_HOTPLUG_E:
case PPME_K8S_E:
case PPME_TRACER_E:
case PPME_MESOS_E:
case PPME_CONTAINER_JSON_E:
case PPME_NOTIFICATION_E:
case PPME_INFRASTRUCTURE_EVENT_E:
case PPME_PAGE_FAULT_E:
return SOURCE_UNKNOWN;
case PPME_TCP_RCV_ESTABLISHED_E:
case PPME_TCP_CLOSE_E:
case PPME_TCP_DROP_E:
case PPME_TCP_RETRANCESMIT_SKB_E:
return KRPOBE;
// TODO add cases of tracepoint, kprobe, uprobe
default:
return SYSCALL_ENTER;
}
} else {
switch (etype) {
case PPME_CONTAINER_X:
case PPME_PROCINFO_X:
case PPME_SCHEDSWITCH_1_X:
case PPME_DROP_X:
case PPME_CPU_HOTPLUG_X:
case PPME_K8S_X:
case PPME_TRACER_X:
case PPME_MESOS_X:
case PPME_CONTAINER_JSON_X:
case PPME_NOTIFICATION_X:
case PPME_INFRASTRUCTURE_EVENT_X:
case PPME_PAGE_FAULT_X:
return SOURCE_UNKNOWN;
// TODO add cases of tracepoint, kprobe, uprobe
default:
return SYSCALL_EXIT;
}
}
}
14 changes: 14 additions & 0 deletions probe/src/cgo/kindling.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ void init_sub_label();
void sub_event(char* eventName, char* category);
uint16_t get_protocol(scap_l4_proto proto);
uint16_t get_type(ppm_param_type type);
uint16_t get_kindling_source(uint16_t etype);

struct event {
string event_name;
ppm_event_type event_type;
Expand Down Expand Up @@ -73,6 +75,18 @@ enum Category {
CAT_SYSTEM = 13, // System-related operations (e.g. reboot)
Category_MAX = 14
};

enum Source {
SOURCE_UNKNOWN = 0,
SYSCALL_ENTER = 1,
SYSCALL_EXIT = 2,
TRACEPOINT = 3,
KRPOBE = 4,
KRETPROBE = 5,
UPROBE = 6,
URETPROBE = 7
};

const static event kindling_to_sysdig[PPM_EVENT_MAX] = {
{"syscall_enter-open", PPME_SYSCALL_OPEN_E},
{"syscall_exit-open", PPME_SYSCALL_OPEN_X},
Expand Down

0 comments on commit 8a1c0bf

Please sign in to comment.