Performance tools, initial check-in
Change-Id: I9fb4f4babecbe02d171f38c4d089634e90141937 Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
committed by
Gerrit Code Review
parent
3640d537e1
commit
52642c3c53
@@ -0,0 +1,5 @@
|
||||
g2_configure_depend = vppinfra-install
|
||||
|
||||
g2_CPPFLAGS = $(call installed_includes_fn, vppinfra)
|
||||
|
||||
g2_LDFLAGS = $(call installed_libs_fn, vppinfra)
|
||||
@@ -0,0 +1,5 @@
|
||||
perftool_configure_depend = vppinfra-install
|
||||
|
||||
perftool_CPPFLAGS = $(call installed_includes_fn, vppinfra)
|
||||
|
||||
perftool_LDFLAGS = $(call installed_libs_fn, vppinfra)
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at:
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
bin_PROGRAMS = g2
|
||||
|
||||
AM_CFLAGS = -Wall
|
||||
|
||||
g2_SOURCES = \
|
||||
clib.c \
|
||||
cpel.c \
|
||||
cpel.h \
|
||||
events.c \
|
||||
g2.h \
|
||||
main.c \
|
||||
menu1.c \
|
||||
pointsel.c \
|
||||
props.c \
|
||||
props.h \
|
||||
g2version.c \
|
||||
view1.c
|
||||
|
||||
g2_LDADD = $(g2_LIBS) -lvppinfra -lpthread -lm
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2009-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <vppinfra/clib.h>
|
||||
#include <vppinfra/vec.h>
|
||||
#include <vppinfra/hash.h>
|
||||
#include <vppinfra/elog.h>
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include "cpel.h"
|
||||
#include "g2.h"
|
||||
|
||||
int widest_track_format;
|
||||
|
||||
typedef struct bound_track_ {
|
||||
u32 track;
|
||||
u8 *track_str;
|
||||
} bound_track_t;
|
||||
|
||||
bound_track_t *bound_tracks;
|
||||
|
||||
uword *the_evtdef_hash; /* (event-id, event-definition) hash */
|
||||
uword *the_trackdef_hash; /* (track-id, track-definition) hash */
|
||||
|
||||
elog_main_t elog_main;
|
||||
|
||||
void *get_clib_event (unsigned int datum)
|
||||
{
|
||||
elog_event_t *ep = vec_elt_at_index (elog_main.events, datum);
|
||||
return (void *)ep;
|
||||
}
|
||||
|
||||
/*
|
||||
* read_clib_file
|
||||
*/
|
||||
int read_clib_file(char *clib_file)
|
||||
{
|
||||
static FILE *ofp;
|
||||
clib_error_t *error = 0;
|
||||
int i;
|
||||
elog_main_t *em = &elog_main;
|
||||
double starttime, delta;
|
||||
|
||||
vec_free(em->events);
|
||||
vec_free(em->event_types);
|
||||
if (the_trackdef_hash)
|
||||
hash_free(the_trackdef_hash);
|
||||
|
||||
the_trackdef_hash = hash_create (0, sizeof (uword));
|
||||
|
||||
error = elog_read_file (&elog_main, clib_file);
|
||||
|
||||
if (error) {
|
||||
fformat(stderr, "%U", format_clib_error, error);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (ofp == NULL) {
|
||||
ofp = fdopen(2, "w");
|
||||
if (ofp == NULL) {
|
||||
fprintf(stderr, "Couldn't fdopen(2)?\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
em = &elog_main;
|
||||
|
||||
for (i = 0; i < vec_len (em->tracks); i++) {
|
||||
u32 track_code;
|
||||
bound_track_t * btp;
|
||||
elog_track_t * t;
|
||||
uword * p;
|
||||
int track_strlen;
|
||||
|
||||
t = &em->tracks[i];
|
||||
track_code = i;
|
||||
p = hash_get(the_trackdef_hash, track_code);
|
||||
if (p) {
|
||||
fprintf(ofp, "track %d redefined, retain first definition\n",
|
||||
track_code);
|
||||
continue;
|
||||
}
|
||||
vec_add2(bound_tracks, btp, 1);
|
||||
btp->track = track_code;
|
||||
btp->track_str = t->name;
|
||||
hash_set(the_trackdef_hash, track_code, btp - bound_tracks);
|
||||
|
||||
track_strlen = strlen((char *)btp->track_str);
|
||||
if (track_strlen > widest_track_format)
|
||||
widest_track_format = track_strlen;
|
||||
}
|
||||
|
||||
initialize_events();
|
||||
|
||||
for (i = 0; i < vec_len (em->event_types); i++) {
|
||||
elog_event_type_t *ep;
|
||||
u8 *tmp;
|
||||
|
||||
ep = vec_elt_at_index(em->event_types, i);
|
||||
tmp = (u8 *) vec_dup(ep->format);
|
||||
vec_add1(tmp,0);
|
||||
add_event_from_clib_file (ep->type_index_plus_one, (char *) tmp, i);
|
||||
vec_free(tmp);
|
||||
}
|
||||
|
||||
finalize_events();
|
||||
|
||||
em->events = elog_get_events (em);
|
||||
|
||||
cpel_event_init(vec_len(em->events));
|
||||
|
||||
starttime = em->events[0].time;
|
||||
|
||||
for (i = 0; i < vec_len (em->events); i++) {
|
||||
elog_event_t *ep;
|
||||
|
||||
ep = vec_elt_at_index(em->events, i);
|
||||
|
||||
delta = ep->time - starttime;
|
||||
|
||||
add_clib_event (delta, ep->track, ep->type + 1, i);
|
||||
}
|
||||
|
||||
cpel_event_finalize();
|
||||
|
||||
set_pid_ax_width(8*widest_track_format);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
AC_INIT(g2, 3.0)
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
AC_CHECK_LIB([vppinfra], [clib_mem_get_page_size],,
|
||||
AC_MSG_ERROR([Please install the vpp-lib package]))
|
||||
AC_CHECK_HEADER([vppinfra/clib.h],,
|
||||
AC_MSG_ERROR([Please install the vpp-dev package]))
|
||||
|
||||
AM_PROG_AS
|
||||
AM_PROG_CC_C_O
|
||||
PKG_CHECK_MODULES(g2, gtk+-2.0)
|
||||
|
||||
AC_OUTPUT([Makefile])
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2005-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _CPEL_H_
|
||||
#define _CPEL_H_ 1
|
||||
|
||||
typedef struct cpel_file_header_ {
|
||||
unsigned char endian_version;
|
||||
unsigned char pad;
|
||||
unsigned short nsections;
|
||||
unsigned file_date;
|
||||
} cpel_file_header_t;
|
||||
|
||||
#define CPEL_FILE_LITTLE_ENDIAN 0x80
|
||||
#define CPEL_FILE_VERSION 0x01
|
||||
#define CPEL_FILE_VERSION_MASK 0x7F
|
||||
|
||||
typedef struct cpel_section_header_ {
|
||||
unsigned int section_type;
|
||||
unsigned int data_length; /* does NOT include type and itself */
|
||||
} cpel_section_header_t;
|
||||
|
||||
#define CPEL_SECTION_STRTAB 1
|
||||
/* string at offset 0 is the name of the table */
|
||||
|
||||
#define CPEL_SECTION_SYMTAB 2
|
||||
#define CPEL_SECTION_EVTDEF 3
|
||||
|
||||
typedef struct event_definition_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_event_definitions;
|
||||
} event_definition_section_header_t;
|
||||
|
||||
typedef struct event_definition_ {
|
||||
unsigned int event;
|
||||
unsigned int event_format;
|
||||
unsigned int datum_format;
|
||||
} event_definition_t;
|
||||
|
||||
#define CPEL_SECTION_TRACKDEF 4
|
||||
|
||||
typedef struct track_definition_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_track_definitions;
|
||||
} track_definition_section_header_t;
|
||||
|
||||
typedef struct track_definition_ {
|
||||
unsigned int track;
|
||||
unsigned int track_format;
|
||||
} track_definition_t;
|
||||
|
||||
#define CPEL_SECTION_EVENT 5
|
||||
|
||||
typedef struct event_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_events;
|
||||
unsigned int clock_ticks_per_second;
|
||||
} event_section_header_t;
|
||||
|
||||
typedef struct event_entry_ {
|
||||
unsigned int time[2];
|
||||
unsigned int track;
|
||||
unsigned int event_code;
|
||||
unsigned int event_datum;
|
||||
} event_entry_t;
|
||||
|
||||
#define CPEL_NUM_SECTION_TYPES 5
|
||||
|
||||
#endif /* _CPEL_H_ */
|
||||
|
||||
+475
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2005-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* typedefs and so forth
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <gtk-2.0/gtk/gtk.h>
|
||||
#include <stdio.h>
|
||||
#include "props.h"
|
||||
|
||||
typedef char boolean;
|
||||
typedef unsigned long long ulonglong;
|
||||
|
||||
/*
|
||||
* main.c
|
||||
*/
|
||||
|
||||
GtkWidget *g_mainwindow;
|
||||
GtkWidget *g_mainvbox;
|
||||
GtkWidget *g_mainhbox;
|
||||
|
||||
/*
|
||||
* pointsel.c
|
||||
*/
|
||||
void point_selector_init(void);
|
||||
boolean read_event_definitions (char *filename);
|
||||
char *sxerox(char *);
|
||||
void pointsel_about(char *);
|
||||
void pointsel_next_snapshot(void);
|
||||
void initialize_events(void);
|
||||
void finalize_events(void);
|
||||
|
||||
#define NEVENTS 100000
|
||||
|
||||
typedef struct event_def_ {
|
||||
ulong event;
|
||||
char *name;
|
||||
char *format;
|
||||
boolean selected;
|
||||
boolean is_clib;
|
||||
char pad[2];
|
||||
} event_def_t;
|
||||
|
||||
event_def_t *find_event_definition (ulong code);
|
||||
|
||||
event_def_t g_eventdefs[NEVENTS];
|
||||
|
||||
/*
|
||||
* config params
|
||||
*/
|
||||
int c_maxpointsel; /* max # points shown in selector dlg */
|
||||
gint c_view1_draw_width;
|
||||
gint c_view1_draw_height;
|
||||
|
||||
/*
|
||||
* menu1.c
|
||||
*/
|
||||
|
||||
void menu1_init(void);
|
||||
void modal_dialog (char *label_text, char *retry_text, char *default_value,
|
||||
boolean (*cb)(char *));
|
||||
void infobox(char *label_text, char *text);
|
||||
/*
|
||||
* view1.c
|
||||
*/
|
||||
GdkFont *g_font;
|
||||
GdkColor fg_black, bg_white;
|
||||
void view1_init(void);
|
||||
void view1_display(void);
|
||||
void view1_read_events_callback(void);
|
||||
void view1_display_when_idle(void);
|
||||
void view1_print_callback(GtkToggleButton *item, gpointer data);
|
||||
void view1_about(char *);
|
||||
void set_pid_ax_width(int width);
|
||||
void set_window_title(const char *filename);
|
||||
|
||||
enum view1_tbox_fn {
|
||||
TBOX_DRAW_BOXED = 1, /* note: order counts */
|
||||
TBOX_DRAW_EVENT,
|
||||
TBOX_DRAW_PLAIN,
|
||||
TBOX_PRINT_BOXED,
|
||||
TBOX_PRINT_EVENT,
|
||||
TBOX_PRINT_PLAIN, /* end restriction */
|
||||
TBOX_GETRECT_BOXED,
|
||||
TBOX_GETRECT_EVENT,
|
||||
TBOX_GETRECT_PLAIN,
|
||||
};
|
||||
|
||||
enum view1_line_fn {
|
||||
LINE_DRAW_BLACK = 1,
|
||||
LINE_DRAW_WHITE,
|
||||
LINE_PRINT,
|
||||
};
|
||||
|
||||
GdkRectangle *tbox (char *s, int x, int y, enum view1_tbox_fn function);
|
||||
void line (int x1, int y1, int x2, int y2, enum view1_line_fn function);
|
||||
gint view1_handle_key_press_event (GtkWidget *widget, GdkEventKey *event);
|
||||
|
||||
/*
|
||||
* events.c
|
||||
*/
|
||||
|
||||
void events_about (char *);
|
||||
|
||||
typedef struct raw_event {
|
||||
unsigned long time[2];
|
||||
unsigned long pid;
|
||||
unsigned long code;
|
||||
unsigned long datum;
|
||||
} raw_event_t;
|
||||
|
||||
void event_init(void);
|
||||
char *mapfile (char *file, ulong *sizep);
|
||||
boolean unmapfile (char *addr, ulong size);
|
||||
void read_events (char *);
|
||||
int find_event_index (ulonglong t);
|
||||
int read_cpel_file(char *file);
|
||||
int read_clib_file(char *file);
|
||||
void cpel_event_init(ulong);
|
||||
void add_event_from_cpel_file(ulong, char * , char *);
|
||||
void add_event_from_clib_file(unsigned int event, char *name,
|
||||
unsigned int vec_index);
|
||||
void add_cpel_event(ulonglong delta, ulong, ulong, ulong);
|
||||
void add_clib_event(double delta, unsigned short track,
|
||||
unsigned short event, unsigned int index);
|
||||
void cpel_event_finalize(void);
|
||||
void *get_clib_event (unsigned int datum);
|
||||
|
||||
typedef struct pid_data {
|
||||
struct pid_data *next;
|
||||
ulong pid_value; /* The actual pid value */
|
||||
ulong pid_index; /* Index in pid sort order */
|
||||
} pid_data_t;
|
||||
|
||||
#define EVENT_FLAG_SELECT 0x00000001 /* This event is selected */
|
||||
#define EVENT_FLAG_SEARCHRSLT 0x00000002 /* This event is the search rslt */
|
||||
#define EVENT_FLAG_CLIB 0x00000004 /* clib event */
|
||||
|
||||
typedef struct pid_sort {
|
||||
struct pid_data *pid;
|
||||
ulong pid_value;
|
||||
/*
|
||||
* This is a bit of a hack, since this is used only by the view:
|
||||
*/
|
||||
unsigned color_index;
|
||||
} pid_sort_t;
|
||||
|
||||
typedef struct event {
|
||||
ulonglong time;
|
||||
ulong code;
|
||||
pid_data_t *pid;
|
||||
ulong datum;
|
||||
ulong flags;
|
||||
} event_t;
|
||||
|
||||
|
||||
boolean g_little_endian;
|
||||
event_t *g_events;
|
||||
ulong g_nevents;
|
||||
pid_sort_t *g_pids;
|
||||
pid_sort_t *g_original_pids;
|
||||
int g_npids;
|
||||
pid_data_t *g_pid_data_list;
|
||||
|
||||
#define PIDHASH_NBUCKETS 20021 /* Should be prime */
|
||||
|
||||
boolean ticks_per_ns_set;
|
||||
double ticks_per_ns;
|
||||
|
||||
/*
|
||||
* version.c
|
||||
*/
|
||||
const char *version_string;
|
||||
const char *minor_v_string;
|
||||
|
||||
/*
|
||||
* cpel.c
|
||||
*/
|
||||
char *get_track_label(unsigned long);
|
||||
int widest_track_format;
|
||||
char *strtab_ref(unsigned long);
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2005-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const char *version_string = "G2 (x86_64 GNU/Linux) major version 3.0";
|
||||
const char *minor_v_string =
|
||||
"Built Wed Feb 3 10:58:12 EST 2016";
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2005-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "g2.h"
|
||||
#include "props.h"
|
||||
#include <pwd.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* globals
|
||||
*/
|
||||
|
||||
GtkWidget *g_mainwindow; /* The main window */
|
||||
|
||||
/* Graphical object heirarchy
|
||||
*
|
||||
* [main window]
|
||||
* [main vbox]
|
||||
* [main (e.g. file) menubar]
|
||||
* [view hbox]
|
||||
* [view bottom menu]
|
||||
*/
|
||||
|
||||
GtkWidget *g_mainvbox;
|
||||
GtkWidget *g_mainhbox;
|
||||
|
||||
gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
/* Allow window to be destroyed */
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
void destroy(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char tmpbuf [128];
|
||||
struct passwd *pw;
|
||||
char *event_file = 0;
|
||||
char *cpel_file = 0;
|
||||
char *clib_file =0;
|
||||
char *title = "none";
|
||||
int curarg=1;
|
||||
char *homedir;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
homedir = getenv ("HOME");
|
||||
tmpbuf[0] = 0;
|
||||
|
||||
if (homedir) {
|
||||
sprintf(tmpbuf, "%s/.g2", homedir);
|
||||
} else {
|
||||
pw = getpwuid(geteuid());
|
||||
if (pw) {
|
||||
sprintf(tmpbuf, "%s/.g2", pw->pw_dir);
|
||||
}
|
||||
}
|
||||
if (tmpbuf[0])
|
||||
readprops(tmpbuf);
|
||||
|
||||
g_mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT(g_mainwindow), "delete_event",
|
||||
GTK_SIGNAL_FUNC (delete_event), NULL);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT(g_mainwindow), "destroy",
|
||||
GTK_SIGNAL_FUNC (destroy), NULL);
|
||||
|
||||
gtk_container_set_border_width(GTK_CONTAINER(g_mainwindow), 5);
|
||||
|
||||
g_mainvbox = gtk_vbox_new(FALSE, 0);
|
||||
g_mainhbox = gtk_hbox_new(FALSE, 0);
|
||||
|
||||
/*
|
||||
* init routines
|
||||
*/
|
||||
|
||||
menu1_init();
|
||||
point_selector_init();
|
||||
view1_init();
|
||||
event_init();
|
||||
|
||||
/*
|
||||
* Now that we're ready to rock 'n roll, see if we've been asked to
|
||||
* press a few buttons...
|
||||
*/
|
||||
|
||||
while (curarg < argc) {
|
||||
if (!strncmp(argv[curarg], "--cpel-input", 4)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
cpel_file = argv[curarg];
|
||||
curarg++;
|
||||
break;
|
||||
}
|
||||
g_error("Missing filename after --cpel-input");
|
||||
}
|
||||
if (!strncmp(argv[curarg], "--clib-input", 4)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
clib_file = argv[curarg];
|
||||
curarg++;
|
||||
break;
|
||||
}
|
||||
g_error("Missing filename after --cpel-input");
|
||||
}
|
||||
|
||||
if (!strncmp(argv[curarg], "--pointdefs", 3)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
read_event_definitions(argv[curarg]);
|
||||
curarg++;
|
||||
continue;
|
||||
}
|
||||
g_error ("Missing filename after --pointdefs\n");
|
||||
}
|
||||
if (!strncmp(argv[curarg], "--event-log", 3)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
event_file = argv[curarg];
|
||||
curarg++;
|
||||
continue;
|
||||
}
|
||||
g_error ("Missing filename after --event-log\n");
|
||||
}
|
||||
|
||||
if (!strncmp(argv[curarg], "--ticks-per-us", 3)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
ticks_per_ns = 0.0;
|
||||
ticks_per_ns = atof(argv[curarg]);
|
||||
if (ticks_per_ns == 0.0) {
|
||||
g_error("ticks-per-ns (%s) didn't convert properly\n",
|
||||
argv[curarg]);
|
||||
}
|
||||
ticks_per_ns_set = TRUE;
|
||||
curarg++;
|
||||
continue;
|
||||
}
|
||||
g_error ("Missing filename after --event-log\n");
|
||||
}
|
||||
|
||||
fprintf(stderr,
|
||||
"g2 [--pointdefs <filename>] [--event-log <filename>]\n");
|
||||
fprintf(stderr, " [--ticks-per-us <value>]\n");
|
||||
fprintf(stderr,
|
||||
" [--cpel-input <filename>] [--clib-input <filename]>\n");
|
||||
fprintf(stderr,
|
||||
"%s\n%s\n", version_string, minor_v_string);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (clib_file) {
|
||||
read_clib_file (clib_file);
|
||||
title = clib_file;
|
||||
} else if (cpel_file) {
|
||||
read_cpel_file(cpel_file);
|
||||
title = cpel_file;
|
||||
} else if (event_file) {
|
||||
read_events(event_file);
|
||||
title = event_file;
|
||||
}
|
||||
|
||||
set_window_title(title);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (g_mainwindow), "key_press_event",
|
||||
(GtkSignalFunc) view1_handle_key_press_event, NULL);
|
||||
gtk_container_add(GTK_CONTAINER(g_mainvbox), g_mainhbox);
|
||||
gtk_widget_show(g_mainhbox);
|
||||
gtk_container_add(GTK_CONTAINER(g_mainwindow), g_mainvbox);
|
||||
gtk_widget_show(g_mainvbox);
|
||||
gtk_widget_show(g_mainwindow);
|
||||
|
||||
gtk_main();
|
||||
return(0);
|
||||
}
|
||||
+565
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 1997-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
time_t now;
|
||||
FILE *ofp;
|
||||
char *dateval;
|
||||
char *username;
|
||||
char *userstr;
|
||||
char *datestr;
|
||||
int i;
|
||||
char propname[32];
|
||||
char *propvalue;
|
||||
char timestr[64];
|
||||
char *cp;
|
||||
|
||||
if (argc < 4) {
|
||||
printf ("usage: mkversion ostype version outputfile\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
ofp = fopen (argv[3], "w");
|
||||
if (ofp == NULL) {
|
||||
printf ("Couldn't create %s\n", argv[3]);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
now = time (0);
|
||||
|
||||
fprintf (ofp, "/*\n");
|
||||
fprintf (ofp, " * G2 Version Stamp, %s",
|
||||
ctime (&now));
|
||||
fprintf (ofp, " * Automatically generated, hand edits are pointless.\n");
|
||||
fprintf (ofp, " */\n\n");
|
||||
|
||||
fprintf (ofp,
|
||||
"const char *version_string = \"G2 (%s) major version %s\";\n",
|
||||
argv[1], argv[2]);
|
||||
|
||||
username = (char *) cuserid (0);
|
||||
|
||||
strcpy(timestr, ctime(&now));
|
||||
|
||||
cp = timestr;
|
||||
|
||||
while (*cp) {
|
||||
cp++;
|
||||
}
|
||||
if (*--cp == '\n')
|
||||
*cp = 0;
|
||||
|
||||
fprintf (ofp,
|
||||
"const char *minor_v_string = \"Built by %s at %s\";\n",
|
||||
username, timestr);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
||||
+854
File diff suppressed because it is too large
Load Diff
+279
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 1997-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <malloc.h>
|
||||
#include <time.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *sxerox (char *s);
|
||||
void exit(int);
|
||||
|
||||
#define NBUCKETS 97
|
||||
|
||||
typedef struct prop_ {
|
||||
struct prop_ *next;
|
||||
char *name;
|
||||
char *value;
|
||||
} prop_t;
|
||||
|
||||
static prop_t *buckets [NBUCKETS];
|
||||
static int hash_shifts[4] = {24, 16, 8, 0};
|
||||
|
||||
/*
|
||||
* getprop
|
||||
*/
|
||||
|
||||
char *getprop (char *name)
|
||||
{
|
||||
unsigned char *cp;
|
||||
unsigned long hash=0;
|
||||
prop_t *bp;
|
||||
int i=0;
|
||||
|
||||
for (cp = (unsigned char *) name; *cp; cp++)
|
||||
hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
|
||||
|
||||
bp = buckets [hash%NBUCKETS];
|
||||
|
||||
while (bp && strcmp (bp->name, name)) {
|
||||
bp = bp->next;
|
||||
}
|
||||
|
||||
if (bp == NULL)
|
||||
return (0);
|
||||
else
|
||||
return (bp->value);
|
||||
}
|
||||
|
||||
/*
|
||||
* getprop_default
|
||||
*/
|
||||
|
||||
char *getprop_default (char *name, char *def)
|
||||
{
|
||||
char *rv;
|
||||
rv = getprop (name);
|
||||
if (rv)
|
||||
return (rv);
|
||||
else
|
||||
return (def);
|
||||
}
|
||||
|
||||
/*
|
||||
* addprop
|
||||
*/
|
||||
|
||||
void addprop (char *name, char *value)
|
||||
{
|
||||
unsigned char *cp;
|
||||
unsigned long hash=0;
|
||||
prop_t **bpp;
|
||||
prop_t *bp;
|
||||
int i=0;
|
||||
|
||||
bp = (prop_t *)g_malloc (sizeof (prop_t));
|
||||
|
||||
bp->next = 0;
|
||||
bp->name = sxerox (name);
|
||||
bp->value = sxerox (value);
|
||||
|
||||
for (cp = (unsigned char *)name; *cp; cp++)
|
||||
hash ^= (*cp)<<(hash_shifts[(i++)&0x3]);
|
||||
|
||||
bpp = &buckets [hash%NBUCKETS];
|
||||
|
||||
if (*bpp == NULL)
|
||||
*bpp = bp;
|
||||
else {
|
||||
bp->next = *bpp;
|
||||
*bpp = bp;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* sxerox
|
||||
*/
|
||||
|
||||
static char *sxerox (char *s)
|
||||
{
|
||||
char *rv = (char *) g_malloc (strlen (s) + 1);
|
||||
strcpy (rv, s);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* readprops
|
||||
*/
|
||||
|
||||
#define START 0
|
||||
#define READNAME 1
|
||||
#define READVALUE 2
|
||||
#define C_COMMENT 3
|
||||
#define CPP_COMMENT 4
|
||||
|
||||
int readprops (char *filename)
|
||||
{
|
||||
FILE *ifp;
|
||||
unsigned char c;
|
||||
int state=START;
|
||||
int linenum=1;
|
||||
char namebuf [128];
|
||||
char valbuf [512];
|
||||
int i;
|
||||
|
||||
ifp = fopen (filename, "r");
|
||||
|
||||
if (ifp == NULL)
|
||||
return (-1);
|
||||
|
||||
while (1) {
|
||||
|
||||
readchar:
|
||||
c = getc (ifp);
|
||||
|
||||
again:
|
||||
switch (state) {
|
||||
case START:
|
||||
if (feof (ifp)) {
|
||||
fclose (ifp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (c == ' ' || c == '\t')
|
||||
goto readchar;
|
||||
|
||||
if (c == '\n') {
|
||||
linenum++;
|
||||
goto readchar;
|
||||
}
|
||||
if (isalpha (c) || (c == '_')) {
|
||||
state = READNAME;
|
||||
goto again;
|
||||
}
|
||||
if (c == '/') {
|
||||
c = getc (ifp);
|
||||
if (c == '/') {
|
||||
state = CPP_COMMENT;
|
||||
goto readchar;
|
||||
} else if (c == '*') {
|
||||
state = C_COMMENT;
|
||||
goto readchar;
|
||||
} else {
|
||||
fprintf (stderr, "unknown token '/' line %d\n",
|
||||
linenum);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
fprintf (stderr, "unknown token '%c' line %d\n",
|
||||
c, linenum);
|
||||
exit (1);
|
||||
break;
|
||||
|
||||
case CPP_COMMENT:
|
||||
while (1) {
|
||||
c = getc (ifp);
|
||||
if (feof (ifp))
|
||||
return (0);
|
||||
if (c == '\n') {
|
||||
linenum++;
|
||||
state = START;
|
||||
goto readchar;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case C_COMMENT:
|
||||
while (1) {
|
||||
c = getc (ifp);
|
||||
if (feof (ifp)) {
|
||||
fprintf (stderr, "unterminated comment, line %d\n",
|
||||
linenum);
|
||||
exit (1);
|
||||
}
|
||||
if (c == '*') {
|
||||
staragain:
|
||||
c = getc (ifp);
|
||||
if (c == '/') {
|
||||
state = START;
|
||||
goto readchar;
|
||||
}
|
||||
if (c == '*')
|
||||
goto staragain;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case READNAME:
|
||||
i = 0;
|
||||
namebuf[i++] = c;
|
||||
while (1) {
|
||||
c = getc (ifp);
|
||||
if (feof (ifp)) {
|
||||
fprintf (stderr, "EOF while reading a name, line %d\n",
|
||||
linenum);
|
||||
exit (1);
|
||||
}
|
||||
if ((!isalnum (c)) && (c != '_')) {
|
||||
namebuf [i] = 0;
|
||||
state = READVALUE;
|
||||
goto again;
|
||||
}
|
||||
namebuf [i++] = c;
|
||||
}
|
||||
break;
|
||||
|
||||
case READVALUE:
|
||||
i = 0;
|
||||
while ((c == ' ') || (c == '\t') || (c == '=')) {
|
||||
c = getc (ifp);
|
||||
if (feof (ifp)) {
|
||||
fprintf (stderr, "EOF while reading a value, line %d\n",
|
||||
linenum);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
goto firsttime;
|
||||
while (1) {
|
||||
c = getc (ifp);
|
||||
|
||||
firsttime:
|
||||
if (c == '\\') {
|
||||
c = getc (ifp);
|
||||
if (feof (ifp)) {
|
||||
fprintf (stderr, "EOF after '\\', line %d\n",
|
||||
linenum);
|
||||
exit (1);
|
||||
}
|
||||
valbuf[i++] = c;
|
||||
continue;
|
||||
}
|
||||
if (c == '\n') {
|
||||
linenum++;
|
||||
while (valbuf [i-1] == ' ' || valbuf[i-1] == '\t')
|
||||
i--;
|
||||
valbuf[i] = 0;
|
||||
addprop (namebuf, valbuf);
|
||||
state = START;
|
||||
goto readchar;
|
||||
}
|
||||
valbuf[i++] = c;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 1997-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
extern char *getprop (char *name);
|
||||
extern char *getprop_default (char *name, char *def);
|
||||
extern void addprop (char *name, char *value);
|
||||
extern int readprops (char *filename);
|
||||
extern int writeprops (char *filename);
|
||||
+3077
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2016 Cisco and/or its affiliates.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at:
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
AM_CFLAGS = -Wall
|
||||
|
||||
bin_PROGRAMS = c2cpel cpelatency cpeldump cpelinreg cpelstate
|
||||
|
||||
lib_LTLIBRARIES = libcperf.la
|
||||
|
||||
libcperf_la_SOURCES = delsvec.c linreg.c props.c cpel_util.c
|
||||
|
||||
TOOL_LIBS = libcperf.la -lvppinfra -lm
|
||||
|
||||
c2cpel_SOURCE = c2cpel.c
|
||||
c2cpel_LDADD = $(TOOL_LIBS)
|
||||
|
||||
cpelatency_SOURCE = cpelatency.c
|
||||
cpelatency_LDADD = $(TOOL_LIBS)
|
||||
|
||||
cpeldump_SOURCE = cpeldump.c
|
||||
cpeldump_LDADD = $(TOOL_LIBS)
|
||||
|
||||
cpelinreg_SOURCE = cpelinreg.c
|
||||
cpelinreg_LDADD = $(TOOL_LIBS)
|
||||
|
||||
cpelstate_SOURCE = cpelstate.c
|
||||
cpelstate_LDADD = $(TOOL_LIBS)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2006-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <vppinfra/clib.h>
|
||||
#include <vppinfra/vec.h>
|
||||
#include <vppinfra/hash.h>
|
||||
#include <vppinfra/elog.h>
|
||||
#include <pwd.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include "cpel.h"
|
||||
#include "cpel_util.h"
|
||||
|
||||
static elog_main_t elog_main;
|
||||
|
||||
/*
|
||||
* convert_clib_file
|
||||
*/
|
||||
void convert_clib_file(char *clib_file)
|
||||
{
|
||||
clib_error_t *error = 0;
|
||||
int i;
|
||||
elog_main_t *em = &elog_main;
|
||||
double starttime, delta;
|
||||
|
||||
error = elog_read_file (&elog_main, clib_file);
|
||||
|
||||
if (error) {
|
||||
clib_warning("%U", format_clib_error, error);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
em = &elog_main;
|
||||
|
||||
starttime = em->events[0].time;
|
||||
|
||||
for (i = 0; i < vec_len (em->events); i++) {
|
||||
elog_event_t *e; /* clib event */
|
||||
evt_t *ep; /* xxx2cpel event */
|
||||
u8 *s;
|
||||
u64 timestamp;
|
||||
elog_event_type_t *t;
|
||||
u8 *brief_event_name;
|
||||
u8 *track_name;
|
||||
int j;
|
||||
|
||||
e = vec_elt_at_index(em->events, i);
|
||||
|
||||
/* Seconds since start of log */
|
||||
delta = e->time - starttime;
|
||||
|
||||
/* u64 nanoseconds since start of log */
|
||||
timestamp = delta * 1e9;
|
||||
|
||||
s = format (0, "%U%c", format_elog_event, em, e, 0);
|
||||
|
||||
/* allocate an event instance */
|
||||
vec_add2(the_events, ep, 1);
|
||||
ep->timestamp = timestamp;
|
||||
|
||||
/* convert string event code to a real number */
|
||||
t = vec_elt_at_index (em->event_types, e->type);
|
||||
|
||||
/*
|
||||
* Construct a reasonable event name.
|
||||
* Truncate the format string at the first whitespace break
|
||||
* or printf format character.
|
||||
*/
|
||||
brief_event_name = format (0, "%s", t->format);
|
||||
|
||||
for (j = 0; j < vec_len (brief_event_name); j++) {
|
||||
if (brief_event_name[j] == ' ' ||
|
||||
brief_event_name[j] == '%' ||
|
||||
brief_event_name[j] == '(') {
|
||||
brief_event_name[j] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Throw away that much of the formatted event */
|
||||
vec_delete (s, j+1, 0);
|
||||
|
||||
ep->event_id = find_or_add_event(brief_event_name, "%s");
|
||||
|
||||
track_name = format (0, "%U%c", format_elog_track, em, e, 0);
|
||||
|
||||
ep->track_id = find_or_add_track (track_name);
|
||||
|
||||
ep->datum = find_or_add_strtab(s);
|
||||
|
||||
vec_free (track_name);
|
||||
vec_free(brief_event_name);
|
||||
vec_free(s);
|
||||
}
|
||||
}
|
||||
|
||||
u8 *vec_basename (char *s)
|
||||
{
|
||||
u8 * rv;
|
||||
char *cp = s;
|
||||
|
||||
while (*cp)
|
||||
cp++;
|
||||
|
||||
cp--;
|
||||
|
||||
while (cp > s && *cp != '/')
|
||||
cp--;
|
||||
|
||||
if (cp > s)
|
||||
cp++;
|
||||
|
||||
rv = format (0, "%s", cp);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int event_compare (const void *a0, const void *a1)
|
||||
{
|
||||
evt_t *e0 = (evt_t *)a0;
|
||||
evt_t *e1 = (evt_t *)a1;
|
||||
|
||||
if (e0->timestamp < e1->timestamp)
|
||||
return -1;
|
||||
else if (e0->timestamp > e1->timestamp)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int curarg=1;
|
||||
char **inputfiles = 0;
|
||||
char *outputfile = 0;
|
||||
FILE *ofp;
|
||||
|
||||
if (argc < 3)
|
||||
goto usage;
|
||||
|
||||
while (curarg < argc) {
|
||||
if (!strncmp(argv[curarg], "--input-file", 3)) {
|
||||
curarg++;
|
||||
if (curarg < argc) {
|
||||
vec_add1 (inputfiles, argv[curarg]);
|
||||
curarg++;
|
||||
continue;
|
||||
}
|
||||
clib_warning("Missing filename after --input-file\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!strncmp(argv[curarg], "--output-file", 3)) {
|
||||
curarg ++;
|
||||
if (curarg < argc) {
|
||||
outputfile = argv[curarg];
|
||||
curarg ++;
|
||||
continue;
|
||||
}
|
||||
clib_warning("Missing filename after --output-file\n");
|
||||
exit(1);
|
||||
}
|
||||
vec_add1 (inputfiles, argv[curarg]);
|
||||
curarg++;
|
||||
continue;
|
||||
|
||||
usage:
|
||||
fformat(stderr,
|
||||
"c2cpel [--input-file] <filename> --output-file <filename>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (vec_len(inputfiles) == 0 || outputfile == 0)
|
||||
goto usage;
|
||||
|
||||
if (vec_len(inputfiles) > 1)
|
||||
goto usage;
|
||||
|
||||
cpel_util_init();
|
||||
|
||||
convert_clib_file (inputfiles[0]);
|
||||
|
||||
ofp = fopen (outputfile, "w");
|
||||
if (ofp == NULL) {
|
||||
clib_unix_warning ("couldn't create %s", outputfile);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
alpha_sort_tracks();
|
||||
fixup_event_tracks();
|
||||
|
||||
/*
|
||||
* Four sections: string-table, event definitions, track defs, events.
|
||||
*/
|
||||
if (!write_cpel_header(ofp, 4)) {
|
||||
clib_warning ("Error writing cpel header to %s...\n", outputfile);
|
||||
unlink(outputfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!write_string_table(ofp)) {
|
||||
clib_warning ("Error writing string table to %s...\n", outputfile);
|
||||
unlink(outputfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!write_event_defs(ofp)) {
|
||||
clib_warning ("Error writing event defs to %s...\n", outputfile);
|
||||
unlink(outputfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!write_track_defs(ofp)) {
|
||||
clib_warning ("Error writing track defs to %s...\n", outputfile);
|
||||
unlink(outputfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!write_events(ofp, (u64) 1e9)) {
|
||||
clib_warning ("Error writing events to %s...\n", outputfile);
|
||||
unlink(outputfile);
|
||||
exit(1);
|
||||
|
||||
}
|
||||
fclose(ofp);
|
||||
exit (0);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
AC_INIT(perftool, 2.0)
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
AC_CHECK_LIB([vppinfra], [clib_mem_get_page_size],,
|
||||
AC_MSG_ERROR([Please install the vpp-lib package]))
|
||||
AC_CHECK_HEADER([vppinfra/clib.h],,
|
||||
AC_MSG_ERROR([Please install the vpp-dev package]))
|
||||
|
||||
AM_PROG_LIBTOOL
|
||||
AM_PROG_CC_C_O
|
||||
|
||||
AC_OUTPUT([Makefile])
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2005-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _CPEL_H_
|
||||
#define _CPEL_H_ 1
|
||||
|
||||
typedef struct cpel_file_header_ {
|
||||
unsigned char endian_version;
|
||||
unsigned char pad;
|
||||
unsigned short nsections;
|
||||
unsigned int file_date;
|
||||
} cpel_file_header_t;
|
||||
|
||||
#define CPEL_FILE_LITTLE_ENDIAN 0x80
|
||||
#define CPEL_FILE_VERSION 0x01
|
||||
#define CPEL_FILE_VERSION_MASK 0x7F
|
||||
|
||||
typedef struct cpel_section_header_ {
|
||||
unsigned int section_type;
|
||||
unsigned int data_length; /* does NOT include type and itself */
|
||||
} cpel_section_header_t;
|
||||
|
||||
#define CPEL_SECTION_STRTAB 1
|
||||
/* string at offset 0 is the name of the table */
|
||||
|
||||
#define CPEL_SECTION_SYMTAB 2
|
||||
#define CPEL_SECTION_EVTDEF 3
|
||||
|
||||
typedef struct event_definition_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_event_definitions;
|
||||
} event_definition_section_header_t;
|
||||
|
||||
typedef struct event_definition_ {
|
||||
unsigned int event;
|
||||
unsigned int event_format;
|
||||
unsigned int datum_format;
|
||||
} event_definition_t;
|
||||
|
||||
#define CPEL_SECTION_TRACKDEF 4
|
||||
|
||||
typedef struct track_definition_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_track_definitions;
|
||||
} track_definition_section_header_t;
|
||||
|
||||
typedef struct track_definition_ {
|
||||
unsigned int track;
|
||||
unsigned int track_format;
|
||||
} track_definition_t;
|
||||
|
||||
#define CPEL_SECTION_EVENT 5
|
||||
|
||||
typedef struct event_section_header_ {
|
||||
char string_table_name[64];
|
||||
unsigned int number_of_events;
|
||||
unsigned int clock_ticks_per_second;
|
||||
} event_section_header_t;
|
||||
|
||||
typedef struct event_entry_ {
|
||||
unsigned int time[2];
|
||||
unsigned int track;
|
||||
unsigned int event_code;
|
||||
unsigned int event_datum;
|
||||
} event_entry_t;
|
||||
|
||||
#define CPEL_NUM_SECTION_TYPES 5
|
||||
|
||||
#endif /* _CPEL_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2006-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __cpel_util_h__
|
||||
#define __cpel_util_h__
|
||||
|
||||
/*
|
||||
* Our idea of an event, as opposed to a CPEL event
|
||||
*/
|
||||
typedef struct evt_ {
|
||||
u64 timestamp;
|
||||
u32 track_id;
|
||||
u32 event_id;
|
||||
u32 datum;
|
||||
} evt_t;
|
||||
|
||||
evt_t *the_events;
|
||||
|
||||
/*
|
||||
* Track object, so we can sort the tracks alphabetically and
|
||||
* fix the events later
|
||||
*/
|
||||
typedef struct track_ {
|
||||
u32 original_index;
|
||||
u32 strtab_offset;
|
||||
} track_t;
|
||||
|
||||
track_t *the_tracks;
|
||||
u32 *track_alpha_map;
|
||||
|
||||
event_definition_t *the_event_definitions;
|
||||
i64 min_timestamp;
|
||||
|
||||
/* Hash tables, used to find previous instances of the same items */
|
||||
uword *the_track_hash;
|
||||
uword *the_msg_event_hash;
|
||||
uword *the_strtab_hash;
|
||||
uword *the_pidtid_hash;
|
||||
uword *the_pid_to_name_hash;
|
||||
u8 *the_strtab;
|
||||
|
||||
u32 find_or_add_strtab(void *s_arg);
|
||||
u32 find_or_add_track(void *s_arg);
|
||||
u32 find_or_add_event(void *s_arg, char *datum_format);
|
||||
int write_string_table(FILE *ofp);
|
||||
int write_cpel_header(FILE *ofp, u32 nsections);
|
||||
int write_event_defs(FILE *ofp);
|
||||
u64 ntohll (u64 x);
|
||||
int write_events(FILE *ofp, u64 clock_ticks_per_second);
|
||||
int write_track_defs(FILE *ofp);
|
||||
void cpel_util_init (void);
|
||||
void alpha_sort_tracks(void);
|
||||
void fixup_event_tracks(void);
|
||||
|
||||
#endif /* __cpel_util_h__ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
*------------------------------------------------------------------
|
||||
* Copyright (c) 2006-2016 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* see "Numerical Recipies in C, 2nd ed." p 665 */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* linreg
|
||||
* Linear regression of (xi, yi), returns parameters for least-squares
|
||||
* fit y = a + bx. Also, compute Pearson's R.
|
||||
*/
|
||||
void linreg (double *x, double *y, int nitems, double *a, double *b,
|
||||
double *minp, double *maxp, double *meanp, double *r)
|
||||
{
|
||||
double sx = 0.0;
|
||||
double sy = 0.0;
|
||||
double st2 = 0.0;
|
||||
double min = y[0];
|
||||
double max = 0.0;
|
||||
double ss, meanx, meany, t;
|
||||
double errx, erry, prodsum, sqerrx, sqerry;
|
||||
int i;
|
||||
|
||||
*b = 0.0;
|
||||
|
||||
for (i = 0; i < nitems; i++) {
|
||||
sx += x[i];
|
||||
sy += y[i];
|
||||
if (y[i] < min)
|
||||
min = y[i];
|
||||
if (y[i] > max)
|
||||
max = y[i];
|
||||
}
|
||||
ss = nitems;
|
||||
meanx = sx / ss;
|
||||
meany = *meanp = sy / ss;
|
||||
*minp = min;
|
||||
*maxp = max;
|
||||
|
||||
for (i = 0; i < nitems; i++) {
|
||||
t = x[i] - meanx;
|
||||
st2 += t*t;
|
||||
*b += t*y[i];
|
||||
}
|
||||
|
||||
*b /= st2;
|
||||
*a = (sy-sx*(*b))/ss;
|
||||
|
||||
prodsum = 0.0;
|
||||
sqerrx = 0.0;
|
||||
sqerry = 0.0;
|
||||
|
||||
/* Compute numerator of Pearson's R */
|
||||
for (i = 0; i < nitems; i++) {
|
||||
errx = x[i] - meanx;
|
||||
erry = y[i] - meany;
|
||||
prodsum += errx * erry;
|
||||
sqerrx += errx*errx;
|
||||
sqerry += erry*erry;
|
||||
}
|
||||
|
||||
*r = prodsum / (sqrt(sqerrx)*sqrt(sqerry));
|
||||
}
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user