/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 4 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"VMPI.h"
// Note, this is not supported in configurations with more than one AvmCore // running in the same process.
#ifdef WIN32 # include "util/WindowsWrapper.h" #else # define __cdecl # include <stdarg.h> # include <string.h> #endif
#include"vprof.h"
#ifndef MIN # define MIN(x, y) ((x) <= (y) ? x : y) #endif #ifndef MAX # define MAX(x, y) ((x) >= (y) ? x : y) #endif
staticinline entry* reverse(entry* s) {
entry_t e, n, p;
p = nullptr; for (e = s; e; e = n) {
n = e->next;
e->next = p;
p = e;
}
return p;
}
staticchar* f(double d) { staticchar s[80]; char* p;
sprintf_s(s, sizeof(s), "%lf", d);
p = s + VMPI_strlen(s) - 1; while (*p == '0') {
*p = '\0';
p--; if (p == s) break;
} if (*p == '.') *p = '\0'; return s;
}
staticvoid dumpProfile(void) {
entry_t e;
entries = reverse(entries);
vprof_printf("event avg [min : max] total count\n"); for (e = entries; e; e = e->next) { if (e->count == 0) continue; // ignore entries with zero count.
vprof_printf("%s", e->file); if (e->line >= 0) {
vprof_printf(":%d", e->line);
}
vprof_printf(" %s [%lld : %lld] %lld %lld ",
f(((double)e->sum) / ((double)e->count)),
(longlongint)e->min, (longlongint)e->max,
(longlongint)e->sum, (longlongint)e->count); if (e->h) { int j = MAXINT; for (j = 0; j < e->h->nbins; j++) {
vprof_printf("(%lld < %lld) ", (longlongint)e->h->count[j],
(longlongint)e->h->lb[j]);
}
vprof_printf("(%lld >= %lld) ", (longlongint)e->h->count[e->h->nbins],
(longlongint)e->h->lb[e->h->nbins - 1]);
} if (e->func) { int j; for (j = 0; j < NUM_EVARS; j++) { if (e->ivar[j] != 0) {
vprof_printf("IVAR%d %d ", j, e->ivar[j]);
}
} for (j = 0; j < NUM_EVARS; j++) { if (e->i64var[j] != 0) {
vprof_printf("I64VAR%d %lld ", j, (longlongint)e->i64var[j]);
}
} for (j = 0; j < NUM_EVARS; j++) { if (e->dvar[j] != 0) {
vprof_printf("DVAR%d %lf ", j, e->dvar[j]);
}
}
}
vprof_printf("\n");
}
entries = reverse(entries);
}
staticinline entry_t findEntry(char* file, int line) { for (entry_t e = entries; e; e = e->next) { if ((e->line == line) && (VMPI_strcmp(e->file, file) == 0)) { return e;
}
} return nullptr;
}
// Initialize the location pointed to by 'id' to a new value profile entry // associated with 'file' and 'line', or do nothing if already initialized. // An optional final argument provides a user-defined probe function.
int initValueProfile(void** id, char* file, int line, ...) {
DO_LOCK(&glock);
entry_t e = (entry_t)*id; if (notInitialized) {
atexit(dumpProfile);
notInitialized = false;
}
if (e == nullptr) {
e = findEntry(file, line); if (e) {
*id = e;
}
}
// Initialize the location pointed to by 'id' to a new histogram profile entry // associated with 'file' and 'line', or do nothing if already initialized.
int initHistProfile(void** id, char* file, int line, int nbins, ...) {
DO_LOCK(&glock);
entry_t e = (entry_t)*id; if (notInitialized) {
atexit(dumpProfile);
notInitialized = false;
}
if (e == nullptr) {
e = findEntry(file, line); if (e) {
*id = e;
}
}
if (e == nullptr) {
va_list va;
hist_t h; int b, n, s;
int64_t* lb;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.