Skip to content

Commit

Permalink
allow dynamic strings in telemeh, use it for nativecall func names
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Apr 19, 2017
1 parent 7df11b9 commit f979442
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/core/nativecall.c
Expand Up @@ -378,6 +378,8 @@ void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib,
MVMint8 keep_sym_name = 0;
MVMint16 i;

unsigned int interval_id = startInterval(tc, "building native call");

MVMObject *entry_point_o = (MVMObject *)MVM_repr_at_key_o(tc, ret_info,
tc->instance->str_consts.entry_point);

Expand All @@ -391,6 +393,7 @@ void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib,
if (!body->lib_handle) {
char *waste[] = { lib_name, NULL };
MVM_free(sym_name);
stopInterval(tc, interval_id, "error building native call");
MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate native library '%s': %s", lib_name, dlerror());
}

Expand All @@ -405,13 +408,16 @@ void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib,
body->entry_point = MVM_nativecall_find_sym(body->lib_handle, sym_name);
if (!body->entry_point) {
char *waste[] = { sym_name, lib_name, NULL };
stopInterval(tc, interval_id, "error building native call");
MVM_exception_throw_adhoc_free(tc, waste, "Cannot locate symbol '%s' in native library '%s'",
sym_name, lib_name);
}
body->sym_name = sym_name;
keep_sym_name = 1;
}

annotateIntervalDynamic(body->entry_point, interval_id, body->sym_name);

if (keep_sym_name == 0) {
MVM_free(sym_name);
}
Expand Down Expand Up @@ -446,6 +452,8 @@ void MVM_nativecall_build(MVMThreadContext *tc, MVMObject *site, MVMString *lib,
#ifdef HAVE_LIBFFI
body->ffi_ret_type = MVM_nativecall_get_ffi_type(tc, body->ret_type);
#endif

stopInterval(tc, interval_id, "nativecall built");
}

static MVMObject * nativecall_cast(MVMThreadContext *tc, MVMObject *target_spec, MVMObject *target_type, void *cpointer_body) {
Expand Down
1 change: 1 addition & 0 deletions src/core/nativecall_dyncall.c
Expand Up @@ -490,6 +490,7 @@ MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type,
dcReset(vm);

interval_id = startInterval(tc, "nativecall invoke");
annotateInterval(entry_point, interval_id, "nc entrypoint");

/* Process arguments. */
for (i = 0; i < num_args; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/core/nativecall_libffi.c
Expand Up @@ -489,6 +489,7 @@ MVMObject * MVM_nativecall_invoke(MVMThreadContext *tc, MVMObject *res_type,
ffi_status status = ffi_prep_cif(&cif, body->convention, (unsigned int)num_args, body->ffi_ret_type, body->ffi_arg_types);

interval_id = startInterval(tc, "nativecall invoke");
annotateInterval(entry_point, interval_id, "nc entrypoint");

/* Process arguments. */
for (i = 0; i < num_args; i++) {
Expand Down
30 changes: 29 additions & 1 deletion src/profiler/telemeh.c
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <string.h>

#ifdef _WIN32
#include <intrin.h>
Expand All @@ -24,7 +25,8 @@ enum RecordType {
TimeStamp,
IntervalStart,
IntervalEnd,
IntervalAnnotation
IntervalAnnotation,
DynamicString
};

struct CalibrationRecord {
Expand All @@ -51,6 +53,11 @@ struct IntervalAnnotation {
const char *description;
};

struct DynamicString {
unsigned int intervalID;
char *description;
};

struct TelemetryRecord {
enum RecordType recordType;

Expand All @@ -62,6 +69,7 @@ struct TelemetryRecord {
struct TimeStampRecord timeStamp;
struct IntervalRecord interval;
struct IntervalAnnotation annotation;
struct DynamicString annotation_dynamic;
};
};

Expand Down Expand Up @@ -151,6 +159,22 @@ void annotateInterval(intptr_t subject, int intervalID, const char *description)
record->annotation.description = description;
}

void annotateIntervalDynamic(intptr_t subject, int intervalID, char *description) {
struct TelemetryRecord *record;
char *temp;

if (!telemetry_active) { return; }

temp = malloc(strlen(description) + 1);
strncpy(temp, description, strlen(description) + 1);

record = newRecord();
record->recordType = DynamicString;
record->threadID = subject;
record->annotation_dynamic.intervalID = intervalID;
record->annotation_dynamic.description = temp;
}

void calibrateTSC(FILE *outfile)
{
unsigned long long startTsc, endTsc;
Expand Down Expand Up @@ -205,6 +229,10 @@ void serializeTelemetryBufferRange(FILE *outfile, unsigned int serializationStar
case IntervalAnnotation:
fprintf(outfile, "%15s ??? Annotation: \"%s\" (%d)\n", " ", record->annotation.description, record->annotation.intervalID);
break;
case DynamicString:
fprintf(outfile, "%15s ??? Annotation: \"%s\" (%d)\n", " ", record->annotation_dynamic.description, record->annotation_dynamic.intervalID);
free(record->annotation_dynamic.description);
break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/profiler/telemeh.h
Expand Up @@ -5,6 +5,7 @@ void takeTimeStamp(intptr_t threadID, const char *description);
unsigned int startInterval(intptr_t threadID, const char *description);
void stopInterval(intptr_t threadID, int intervalID, const char *description);
void annotateInterval(intptr_t subject, int intervalID, const char *description);
void annotateIntervalDynamic(intptr_t subject, int intervalID, char *description);

void initTelemetry(FILE *outfile);
void finishTelemetry();

0 comments on commit f979442

Please sign in to comment.