1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
/* Copyright (C) 2021 Free Software Foundation, Inc.
Contributed by Oracle.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef _EEXPERIMENT_H
#define _EEXPERIMENT_H
// The experiment class is responsible for managing all the data
// for an individual experiment
#include "Metric.h"
#include "Histable.h"
#include "Stats_data.h"
#include "DefaultMap.h"
#include "HeapMap.h"
class Data_window;
class DbeFile;
class CallStack;
class JMethod;
class Sample;
class SegMem;
class LoadObject;
class SourceFile;
class UserLabel;
class PRBTree;
class Emsg;
class Emsgqueue;
struct JThread;
struct GCEvent;
class FileData;
class Module;
class Experiment;
template <class ITEM> class Vector;
#define JTHREAD_DEFAULT ((JThread*)0)
#define JTHREAD_NONE ((JThread*)-1)
// When we perform the pipelined optimization on resolve_frame_info() and add_stack()
// this is the number of iterations one phase works on before passing on the work to
// the next phase
#define CSTCTX_CHUNK_SZ 10000
#define PIPELINE_QUEUE_SZ_HI 8
#define PIPELINE_QUEUE_SZ_LOW 2
// the add_stack_ctx structure contains the intermediate state (context) after
// CSTCTX_CHUNK_SZ number of iterations to pass on the work to another thread to
// operate on the next stage
typedef struct
{
Vector<DbeInstr*> *natpcs;
Vector<Histable*> *jpcs;
long idx;
FramePacket *frp;
hrtime_t tstamp;
uint32_t thrid;
bool last_ctx;
} cstk_ctx;
// To minimize threadpool overhead, the granularity of a job submitted is made larger:
// containing a chunk of iterations (of size CSTCTX_CHUNK_SZ)
typedef struct
{
cstk_ctx* cstCtxAr[CSTCTX_CHUNK_SZ];
int last_idx;
long idx_begin;
long idx_end;
DataDescriptor *dDscr;
Experiment *exp;
void *cstk;
} cstk_ctx_chunk;
class Experiment : public Histable, public DbeMessages
{
public:
enum Exp_status
{
SUCCESS,
INCOMPLETE,
FAILURE
};
Experiment ();
virtual ~Experiment ();
virtual Histable_type
get_type ()
{
return EXPERIMENT;
};
virtual Vector<Histable*> *get_comparable_objs ();
int groupId;
Experiment *founder_exp; // parent of this experiment
Vector<Experiment*> *children_exps; // children of this experiment
// Configuration Information
char *hostname; // Hosthame (e.g. mymachine)
hrtime_t start_sec; // Starting timeval secs.
char *username; // name of person performing the test
char *architecture; // Architecture name ("sun4")
Platform_t platform; // Sparc,Sparcv9,Intel
WSize_t wsize; // word size: may be w32 or w64
int clock; // CPU clock frequency, Mhz
int varclock; // Set if CPU clock frequency can change: turbo-mode
int maxclock; // max. CPU clock frequency on MP machine
int minclock; // min. CPU clock frequency on MP machine
int ncpus; // count of CPUs where expt was recorded
int hw_cpuver; // CPU version from libcpc
char *machinemodel; // machine model of machine on which experiment was recorded
char *os_version; // Operating system name
int page_size; // Page size (bytes)
int npages; // Number of page size
int exp_maj_version; // major version number of current experiment
int exp_min_version; // minor version number of current experiment
int hex_field_width; // number of digits in hex form of address
// for current experiment, i.e. 8 for 32bit addresses
int broken; // If SP_JCMD_RUN line not seen
int obsolete; // If pointer file experiment detected
bool hwc_default; // True if HW counters were enabled by default
int hwc_bogus; // Count of bogus HWC packets
int hwc_lost_int; // Count of packets reflecting lost interrupt
int hwc_scanned; // If the HWC packets have been scanned
int invalid_packet; // Count of invalid packets
bool exec_started; // True if exec was called, and exec error not yet seen
bool dataspaceavail; // True if dataspace data is in the experiment
bool leaklistavail; // True if leaklist data is in the experiment
bool heapdataavail; // True if heap data is in the experiment
bool racelistavail; // true if there are race events in the experiment
bool iodataavail; // true if there are io events in the experiment
bool deadlocklistavail; // true if there are deadlock events in the experiment
bool timelineavail; // true if there are valid timestamps in the experiment
bool ifreqavail; // True if instruction-frequency data is in the experiment
bool ompavail; // true if there is OpenMP data in the experiment
bool has_java;
char *uarglist; // argv[] array, as a string
char *utargname; // basename of argv[0] extracted from uarglist
char *ucwd; // working directory
char *cversion; // collector version string
char *dversion; // driver version string (er_kernel)
char *jversion; // Java version string (java profiling)
// Open the named experiment record and process log file
Exp_status open (char *directory_name);
// Update experiment (read and process new data)
Exp_status update ();
// Returns collector parameters for the current sample selection
Collection_params *
get_params ()
{
return &coll_params;
}
Exp_status
get_status ()
{
return status;
}
// Returns the number of samples. For use by FilterNumeric
int
nsamples ()
{
return samples->size ();
}
// Release any releasable memory.
void purge ();
void resetShowHideStack ();
int save_notes (char*, bool);
int delete_notes (bool);
Experiment *getBaseFounder (); // returns topmost founder or this if no descendents
hrtime_t
getStartTime ()
{
return exp_start_time;
}
hrtime_t getRelativeStartTime (); // delta between start and founder's start
hrtime_t
getWallStartSec ()
{
return start_sec;
}
hrtime_t
getLastEvent ()
{
if (last_event != ZERO_TIME)
return last_event;
return exp_start_time;
}
hrtime_t
getGCDuration ()
{
return gc_duration;
}
int
getPID ()
{
return pid;
}
int
getUserExpId ()
{
return userExpId;
}
int
getExpIdx ()
{
return expIdx;
}
void
setExpIdx (int idx)
{
expIdx = idx;
}
void
setUserExpId (int idx)
{
userExpId = idx;
}
void
setTinyThreshold (int limit)
{
tiny_threshold = limit;
}
bool
isDiscardedTinyExperiment ()
{
return discardTiny;
}
Exp_status open_epilogue ();
void read_experiment_data (bool read_ahead);
static int copy_file_to_archive (const char *name, const char *aname, int hide_msg);
static int copy_file_to_common_archive (const char *name, const char *aname,
int hide_msg, const char *common_archive, int relative_path = 0);
static int copy_file (char *name, char *aname, int hide_msg,
char *common_archive = NULL, int relative_path = 0);
// get_raw_events()
// action: get unfiltered packets, loading them if required
// parameters: data_id (see ProfData_type)
DataDescriptor *get_raw_events (int data_id);
Vector<DataDescriptor*> *getDataDescriptors ();
// Some DATA_* types are derived from others, e.g. DATA_HEAPSZ is derived from DATA_HEAP
// The following hooks support derived DataViews
int base_data_id (int data_id); // returns base data_id type (ProfData_type DATA_*)
DataView *create_derived_data_view (int data_id, DataView *dview);
Vector<BaseMetric*>*
get_metric_list ()
{
return metrics;
}
char *
get_expt_name ()
{
return expt_name; // Return the pathname to the experiment
};
Vector<char*> *get_descendants_names ();
char *get_fndr_arch_name ();
char *get_arch_name ();
char *getNameInArchive (const char *fname, bool archiveFile = false);
char *checkFileInArchive (const char *fname, bool archiveFile = false);
DbeFile *findFileInArchive (const char *className, const char *runTimePath);
DbeFile *findFileInArchive (const char *fname);
bool create_dir (char *dname);
Vaddr
ret_stack_base ()
{
return stack_base;
};
// Map a virtual address to a PC pair
DbeInstr *map_Vaddr_to_PC (Vaddr addr, hrtime_t ts);
DbeInstr *map_jmid_to_PC (Vaddr mid, int lineno, hrtime_t ts);
Sample *map_event_to_Sample (hrtime_t ts);
GCEvent *map_event_to_GCEvent (hrtime_t ts);
DataView *
getOpenMPdata ()
{
return openMPdata;
}
time_t
get_mtime ()
{
return mtime;
}
Emsg *fetch_comments (void); // fetch the queue of comment messages
Emsg *fetch_runlogq (void); // fetch the queue of run log messages
Emsg *fetch_errors (void); // fetch the queue of error messages
Emsg *fetch_warnings (void); // fetch the queue of warning messages
Emsg *fetch_notes (void); // fetch the queue of notes messages
Emsg *fetch_ifreq (void); // fetch the queue of ifreq messages
Emsg *fetch_pprocq (void); // fetch the queue of post-processing messages
// message queues
Emsgqueue *commentq; // comments for the experiment header
Emsgqueue *runlogq; // used temporarily; after log file processing,
// messages are appended to the commentq
Emsgqueue *errorq; // error messages
Emsgqueue *warnq; // warning messages
Emsgqueue *notesq; // user-written notes messages
Emsgqueue *pprocq; // postprocessing messages
Emsgqueue *ifreqq; // Instruction frequency data, from count experiment
Map<const char*, LoadObject*> *loadObjMap;
Vector<LoadObject*> *loadObjs;
void append (LoadObject *lo);
LoadObject *createLoadObject (const char *path, uint64_t chksum = 0);
LoadObject *createLoadObject (const char *path, const char *runTimePath);
SourceFile *get_source (const char *path);
void set_clock (int clk);
CallStack *
callTree ()
{
return cstack;
}
CallStack *
callTreeShowHide ()
{
return cstackShowHide;
}
uint32_t mapTagValue (Prop_type, uint64_t value);
Histable *getTagObj (Prop_type, uint32_t idx);
Vector<Histable*> *getTagObjs (Prop_type);
JThread *map_pckt_to_Jthread (uint32_t tid, hrtime_t tstamp);
JThread *get_jthread (uint32_t tid);
Vector<JThread*> *
get_jthreads ()
{
return jthreads;
}
Vector<GCEvent*> *
get_gcevents ()
{
return gcevents;
}
bool need_swap_endian;
Collection_params coll_params; // Collection params
// Ranges for threads, lwps, cpu
uint64_t min_thread;
uint64_t max_thread;
uint64_t thread_cnt;
uint64_t min_lwp;
uint64_t max_lwp;
uint64_t lwp_cnt;
uint64_t min_cpu;
uint64_t max_cpu;
uint64_t cpu_cnt;
uint64_t dsevents; // count of dataspace events
uint64_t dsnoxhwcevents; /* count of ds events that could be be validated
* because of no branch target info */
PacketDescriptor *newPacketDescriptor (int kind, DataDescriptor *dDscr);
PacketDescriptor *getPacketDescriptor (int kind);
// debugging aids -- dump_stacks, dump_map
void dump_stacks (FILE *);
void dump_map (FILE *);
// These methods are used in nightly performance regression testing
void DBG_memuse (Sample *);
void DBG_memuse (const char *sname);
void init_cache ();
DefaultMap<int64_t, FileData*> *
getFDataMap ()
{
return fDataMap;
}
CallStack *cstack;
protected:
Exp_status status; // Error status
Vector<SegMem*> *seg_items; // Master list of seg_items
CallStack *cstackShowHide;
PRBTree *maps; // All maps in (Vaddr,time)
hrtime_t gc_duration; // wall-clock hrtime of total GC intervals
hrtime_t exp_start_time; // wall-clock hrtime at exp start
hrtime_t last_event; // wall-clock hrtime of last known sample or log.xml entry
hrtime_t non_paused_time; // sum of periods where data collection is active (not paused)
hrtime_t resume_ts; // tracks log.xml start/resume times
void update_last_event (hrtime_t ts /*wall time (not 0-based)*/);
char *expt_name; // name of experiment
char *arch_name; // <experiment>/archive
char *fndr_arch_name; // <founder_experiment>/archive
char *dyntext_name; // <experiment>/dyntext
int yyparse (); // Allow yyparse actions to access
Vaddr stack_base; // Stack base
// Write experiment header to comment queue
void write_header ();
void write_coll_params ();
Exp_status find_expdir (char *directory_name);
// Invoke the parser to process a file.
void read_data_file (const char*, const char*);
int read_log_file ();
void read_labels_file ();
void read_notes_file ();
void read_archives ();
int read_java_classes_file ();
void read_map_file ();
int read_overview_file ();
int read_dyntext_file ();
void read_omp_file ();
void read_omp_preg ();
void read_omp_task ();
void read_ifreq_file ();
void read_frameinfo_file ();
// Functions to process the log and loadobjects file entries
// They are deliberately made virtual to overload them
// in er_export.
virtual int process_arglist_cmd (char *, char *);
virtual int process_desc_start_cmd (char *, hrtime_t, char *, char *, int, char *);
virtual int process_desc_started_cmd (char *, hrtime_t, char *, char *, int, char *);
virtual int process_fn_load_cmd (Module *mod, char *fname, Vaddr vaddr, int fsize, hrtime_t ts);
virtual int process_fn_unload_cmd (char *, Vaddr, hrtime_t);
virtual int process_hwcounter_cmd (char *, int, char *, char *, int, int, int, char *);
virtual int process_hwsimctr_cmd (char *, int, char *, char *, char*, int, int, int, int, int);
virtual int process_jcm_load_cmd (char*, Vaddr, Vaddr, int, hrtime_t);
virtual int process_jcm_unload_cmd (char*, Vaddr, hrtime_t);
virtual int process_Linux_kernel_cmd (hrtime_t);
virtual int process_jthr_end_cmd (char *, uint64_t, Vaddr, Vaddr, hrtime_t);
virtual int process_jthr_start_cmd (char *, char *, char *, char *, uint64_t, Vaddr, Vaddr, hrtime_t);
virtual int process_gc_end_cmd (hrtime_t);
virtual int process_gc_start_cmd (hrtime_t);
virtual int process_sample_cmd (char *, hrtime_t, int id, char *lbl);
virtual int process_sample_sig_cmd (char *, int);
virtual int process_seg_map_cmd (char *, hrtime_t, Vaddr, int, int, int64_t, int64_t, int64_t, char *);
virtual int process_seg_unmap_cmd (char *, hrtime_t, Vaddr);
// creation time for experiment
time_t mtime;
hrtime_t exp_rel_start_time; // start of exp. relative to founder
bool exp_rel_start_time_set;
Vector<UserLabel*> *userLabels; // List of er_labels
int userExpId; // user value for EXPID
int expIdx; // DbeSession exp identifier
PRBTree *jmaps; // JAVA_CLASSES: (id,time)->Histable
Experiment* baseFounder; // outermost experiment (null until lazily computed)
// Represents a file in experiment
class ExperimentFile;
// XML handler to parse various experiment files
class ExperimentHandler;
class ExperimentLabelsHandler;
uint64_t readPacket (Data_window *dwin, Data_window::Span *span);
void readPacket (Data_window *dwin, char *ptr, PacketDescriptor *pDscr,
DataDescriptor *dDscr, int arg, uint64_t pktsz);
// read data
DataDescriptor *get_profile_events ();
DataDescriptor *get_sync_events ();
DataDescriptor *get_hwc_events ();
DataDescriptor *get_heap_events ();
DataDescriptor *get_heapsz_events ();
DataDescriptor *get_iotrace_events ();
DataDescriptor *get_race_events ();
DataDescriptor *get_deadlock_events ();
DataDescriptor *get_sample_events ();
DataDescriptor *get_gc_events ();
DataDescriptor *getDataDescriptor (int data_id);
DataDescriptor *newDataDescriptor (int data_id, int flags = 0,
DataDescriptor *master_dDscr = NULL);
// Frame info data structures and methods
struct UIDnode;
struct RawFramePacket;
Vector<RawFramePacket*>*frmpckts; // frame info data
static int frUidCmp (const void*, const void*);
RawFramePacket *find_frame_packet (uint64_t uid);
static const int CHUNKSZ = 16384;
long nnodes;
long nchunks;
UIDnode **chunks;
UIDnode **uidHTable;
Vector<UIDnode*> *uidnodes;
bool resolveFrameInfo;
bool discardTiny;
int tiny_threshold; /* optimize away tiny experiments which ran
* for less than specified time (ms): default 0 */
static int uidNodeCmp (const void *a, const void *b);
UIDnode *add_uid (Data_window *dwin, uint64_t uid, int size, uint32_t *array, uint64_t link_uid);
UIDnode *add_uid (Data_window *dwin, uint64_t uid, int size, uint64_t *array, uint64_t link_uid);
UIDnode *new_uid_node (uint64_t uid, uint64_t val);
UIDnode *get_uid_node (uint64_t uid, uint64_t val);
UIDnode *get_uid_node (uint64_t uid);
UIDnode *find_uid_node (uint64_t uid);
ExperimentFile *logFile;
// Data descriptors
Vector<DataDescriptor*> *dataDscrs;
Vector<PacketDescriptor*> *pcktDscrs;
long blksz; // binary data file block size
// Processed data packets
DataView *openMPdata; // OMP fork events
// Map events to OpenMP parallel regions and tasks
Map2D<uint32_t, hrtime_t, uint64_t> *mapPRid;
Map2D<uint32_t, hrtime_t, void*> *mapPReg;
Map2D<uint32_t, hrtime_t, void*> *mapTask;
// Archive content
Map<const char*, DbeFile *> *archiveMap;
Map<const char*, SourceFile*>*sourcesMap;
void init ();
void fini ();
void post_process ();
void constructJavaStack (FramePacket *, UIDnode *, Map<uint64_t, uint64_t> *);
void resolve_frame_info (DataDescriptor*);
void cleanup_cstk_ctx_chunk ();
void register_metric (Metric::Type type);
void register_metric (Hwcentry *ctr, const char* aux, const char* username);
Sample *sample_last_used;
GCEvent *gcevent_last_used;
char *first_sample_label;
Module *get_jclass (const char *className, const char *fileName);
LoadObject *get_j_lo (const char *className, const char *fileName);
Vector<BaseMetric*> *metrics;
Vector<JThread*> *jthreads; // master list of Java threads
Vector<JThread*> *jthreads_idx; // index in the master list
Vector<GCEvent*> *gcevents;
Vector<UnmapChunk*> *heapUnmapEvents;
Vector<Sample*> *samples; // Array of Sample pointers
DefaultMap<int64_t, FileData*> *fDataMap; // list of FileData objects using the virtual File descriptor as the key
DefaultMap<int, int64_t> *vFdMap; // list of virtual file descrptors using the file descriptor as the key
Vector<Vector<Histable*>*> *tagObjs; // tag objects
bool sparse_threads;
SegMem **smemHTable; // hash table for SegMem's
DbeInstr **instHTable; // hash table for DbeInstr
Map<unsigned long long, JMethod*> *jmidHTable; // hash table for jmid
// identity of target process
int pid;
int ppid;
int pgrp;
int sid;
// Map file processing related data
struct MapRecord
{
enum
{
LOAD, UNLOAD
} kind;
Histable *obj;
Vaddr base;
Size size;
hrtime_t ts;
uint64_t foff;
};
void mrec_insert (MapRecord *mrec);
SegMem *update_ts_in_maps (Vaddr addr, hrtime_t ts);
int read_warn_file ();
LoadObject *get_dynfunc_lo (const char *loName);
Function *create_dynfunc (Module *mod, char *fname, int64_t vaddr, int64_t fsize);
char *get_archived_name (const char *fname, bool archiveFile = false);
Vector<MapRecord*> *mrecs;
private:
void add_evt_time_to_profile_events (DataDescriptor *dDscr);
DataView *create_heapsz_data_view (DataView *heap_dview);
void compute_heapsz_data_view (DataView *heapsz_dview);
};
struct JThread
{
JThread *next;
char *name;
char *group_name;
char *parent_name;
uint32_t tid; // system thread id
Vaddr jthr; // recorded Java thread id
Vaddr jenv; // recorded JNIEnv id
uint32_t jthr_id; // internal JThread object id
hrtime_t start;
hrtime_t end;
JThread ()
{
name = NULL;
group_name = NULL;
parent_name = NULL;
}
~JThread ()
{
free (name);
free (group_name);
free (parent_name);
}
bool is_system ();
};
struct GCEvent
{
GCEvent ()
{
id = -1;
}
~GCEvent () { }
hrtime_t start;
hrtime_t end;
int id;
};
class ExperimentLoadCancelException
{
public:
ExperimentLoadCancelException () { };
~ExperimentLoadCancelException () { };
};
#endif /* _EEXPERIMENT_H */
|