1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #ifndef _EEXPERIMENT_H
22 #define _EEXPERIMENT_H
24 // The experiment class is responsible for managing all the data
25 // for an individual experiment
29 #include "Stats_data.h"
30 #include "DefaultMap.h"
50 template <class ITEM> class Vector;
52 #define JTHREAD_DEFAULT ((JThread*)0)
53 #define JTHREAD_NONE ((JThread*)-1)
55 // When we perform the pipelined optimization on resolve_frame_info() and add_stack()
56 // this is the number of iterations one phase works on before passing on the work to
59 #define CSTCTX_CHUNK_SZ 10000
60 #define PIPELINE_QUEUE_SZ_HI 8
61 #define PIPELINE_QUEUE_SZ_LOW 2
63 // the add_stack_ctx structure contains the intermediate state (context) after
64 // CSTCTX_CHUNK_SZ number of iterations to pass on the work to another thread to
65 // operate on the next stage
68 Vector<DbeInstr*> *natpcs;
69 Vector<Histable*> *jpcs;
77 // To minimize threadpool overhead, the granularity of a job submitted is made larger:
78 // containing a chunk of iterations (of size CSTCTX_CHUNK_SZ)
81 cstk_ctx* cstCtxAr[CSTCTX_CHUNK_SZ];
85 DataDescriptor *dDscr;
90 class Experiment : public Histable, public DbeMessages
102 virtual ~Experiment ();
104 virtual Histable_type
109 virtual Vector<Histable*> *get_comparable_objs ();
112 Experiment *founder_exp; // parent of this experiment
113 Vector<Experiment*> *children_exps; // children of this experiment
115 // Configuration Information
116 char *hostname; // Hosthame (e.g. mymachine)
117 hrtime_t start_sec; // Starting timeval secs.
118 char *username; // name of person performing the test
119 char *architecture; // Architecture name ("sun4")
120 Platform_t platform; // Sparc,Sparcv9,Intel
121 WSize_t wsize; // word size: may be w32 or w64
122 int clock; // CPU clock frequency, Mhz
123 int varclock; // Set if CPU clock frequency can change: turbo-mode
124 int maxclock; // max. CPU clock frequency on MP machine
125 int minclock; // min. CPU clock frequency on MP machine
126 int ncpus; // count of CPUs where expt was recorded
127 int hw_cpuver; // CPU version from libcpc
128 char *machinemodel; // machine model of machine on which experiment was recorded
129 char *os_version; // Operating system name
130 int page_size; // Page size (bytes)
131 int npages; // Number of page size
132 int exp_maj_version; // major version number of current experiment
133 int exp_min_version; // minor version number of current experiment
134 int hex_field_width; // number of digits in hex form of address
135 // for current experiment, i.e. 8 for 32bit addresses
136 int broken; // If SP_JCMD_RUN line not seen
137 int obsolete; // If pointer file experiment detected
138 bool hwc_default; // True if HW counters were enabled by default
139 int hwc_bogus; // Count of bogus HWC packets
140 int hwc_lost_int; // Count of packets reflecting lost interrupt
141 int hwc_scanned; // If the HWC packets have been scanned
142 int invalid_packet; // Count of invalid packets
143 bool exec_started; // True if exec was called, and exec error not yet seen
144 bool dataspaceavail; // True if dataspace data is in the experiment
145 bool leaklistavail; // True if leaklist data is in the experiment
146 bool heapdataavail; // True if heap data is in the experiment
147 bool racelistavail; // true if there are race events in the experiment
148 bool iodataavail; // true if there are io events in the experiment
149 bool deadlocklistavail; // true if there are deadlock events in the experiment
150 bool timelineavail; // true if there are valid timestamps in the experiment
151 bool ifreqavail; // True if instruction-frequency data is in the experiment
152 bool ompavail; // true if there is OpenMP data in the experiment
154 char *uarglist; // argv[] array, as a string
155 char *utargname; // basename of argv[0] extracted from uarglist
156 char *ucwd; // working directory
157 char *cversion; // collector version string
158 char *dversion; // driver version string (er_kernel)
159 char *jversion; // Java version string (java profiling)
161 // Open the named experiment record and process log file
162 Exp_status open (char *directory_name);
164 // Update experiment (read and process new data)
165 Exp_status update ();
167 // Returns collector parameters for the current sample selection
180 // Returns the number of samples. For use by FilterNumeric
184 return samples->size ();
187 // Release any releasable memory.
190 void resetShowHideStack ();
191 int save_notes (char*, bool);
192 int delete_notes (bool);
193 Experiment *getBaseFounder (); // returns topmost founder or this if no descendents
198 return exp_start_time;
200 hrtime_t getRelativeStartTime (); // delta between start and founder's start
211 if (last_event != ZERO_TIME)
213 return exp_start_time;
247 setUserExpId (int idx)
253 setTinyThreshold (int limit)
255 tiny_threshold = limit;
259 isDiscardedTinyExperiment ()
264 Exp_status open_epilogue ();
265 void read_experiment_data (bool read_ahead);
266 static int copy_file_to_archive (const char *name, const char *aname, int hide_msg);
267 static int copy_file_to_common_archive (const char *name, const char *aname,
268 int hide_msg, const char *common_archive, int relative_path = 0);
269 static int copy_file (char *name, char *aname, int hide_msg,
270 char *common_archive = NULL, int relative_path = 0);
273 // action: get unfiltered packets, loading them if required
274 // parameters: data_id (see ProfData_type)
275 DataDescriptor *get_raw_events (int data_id);
276 Vector<DataDescriptor*> *getDataDescriptors ();
278 // Some DATA_* types are derived from others, e.g. DATA_HEAPSZ is derived from DATA_HEAP
279 // The following hooks support derived DataViews
280 int base_data_id (int data_id); // returns base data_id type (ProfData_type DATA_*)
281 DataView *create_derived_data_view (int data_id, DataView *dview);
292 return expt_name; // Return the pathname to the experiment
295 Vector<char*> *get_descendants_names ();
296 char *get_fndr_arch_name ();
297 char *get_arch_name ();
298 char *getNameInArchive (const char *fname, bool archiveFile = false);
299 char *checkFileInArchive (const char *fname, bool archiveFile = false);
300 DbeFile *findFileInArchive (const char *className, const char *runTimePath);
301 DbeFile *findFileInArchive (const char *fname);
302 bool create_dir (char *dname);
310 // Map a virtual address to a PC pair
311 DbeInstr *map_Vaddr_to_PC (Vaddr addr, hrtime_t ts);
312 DbeInstr *map_jmid_to_PC (Vaddr mid, int lineno, hrtime_t ts);
313 Sample *map_event_to_Sample (hrtime_t ts);
314 GCEvent *map_event_to_GCEvent (hrtime_t ts);
328 Emsg *fetch_comments (void); // fetch the queue of comment messages
329 Emsg *fetch_runlogq (void); // fetch the queue of run log messages
330 Emsg *fetch_errors (void); // fetch the queue of error messages
331 Emsg *fetch_warnings (void); // fetch the queue of warning messages
332 Emsg *fetch_notes (void); // fetch the queue of notes messages
333 Emsg *fetch_ifreq (void); // fetch the queue of ifreq messages
334 Emsg *fetch_pprocq (void); // fetch the queue of post-processing messages
337 Emsgqueue *commentq; // comments for the experiment header
338 Emsgqueue *runlogq; // used temporarily; after log file processing,
339 // messages are appended to the commentq
340 Emsgqueue *errorq; // error messages
341 Emsgqueue *warnq; // warning messages
342 Emsgqueue *notesq; // user-written notes messages
343 Emsgqueue *pprocq; // postprocessing messages
344 Emsgqueue *ifreqq; // Instruction frequency data, from count experiment
345 Map<const char*, LoadObject*> *loadObjMap;
346 Vector<LoadObject*> *loadObjs;
347 void append (LoadObject *lo);
348 LoadObject *createLoadObject (const char *path, uint64_t chksum = 0);
349 LoadObject *createLoadObject (const char *path, const char *runTimePath);
350 SourceFile *get_source (const char *path);
351 void set_clock (int clk);
362 return cstackShowHide;
365 uint32_t mapTagValue (Prop_type, uint64_t value);
366 Histable *getTagObj (Prop_type, uint32_t idx);
367 Vector<Histable*> *getTagObjs (Prop_type);
369 JThread *map_pckt_to_Jthread (uint32_t tid, hrtime_t tstamp);
370 JThread *get_jthread (uint32_t tid);
384 bool need_swap_endian;
385 Collection_params coll_params; // Collection params
387 // Ranges for threads, lwps, cpu
397 uint64_t dsevents; // count of dataspace events
398 uint64_t dsnoxhwcevents; /* count of ds events that could be be validated
399 * because of no branch target info */
401 PacketDescriptor *newPacketDescriptor (int kind, DataDescriptor *dDscr);
402 PacketDescriptor *getPacketDescriptor (int kind);
404 // debugging aids -- dump_stacks, dump_map
405 void dump_stacks (FILE *);
406 void dump_map (FILE *);
408 // These methods are used in nightly performance regression testing
409 void DBG_memuse (Sample *);
410 void DBG_memuse (const char *sname);
413 DefaultMap<int64_t, FileData*> *
422 Exp_status status; // Error status
423 Vector<SegMem*> *seg_items; // Master list of seg_items
424 CallStack *cstackShowHide;
425 PRBTree *maps; // All maps in (Vaddr,time)
427 hrtime_t gc_duration; // wall-clock hrtime of total GC intervals
428 hrtime_t exp_start_time; // wall-clock hrtime at exp start
429 hrtime_t last_event; // wall-clock hrtime of last known sample or log.xml entry
430 hrtime_t non_paused_time; // sum of periods where data collection is active (not paused)
431 hrtime_t resume_ts; // tracks log.xml start/resume times
432 void update_last_event (hrtime_t ts /*wall time (not 0-based)*/);
434 char *expt_name; // name of experiment
435 char *arch_name; // <experiment>/archive
436 char *fndr_arch_name; // <founder_experiment>/archive
437 char *dyntext_name; // <experiment>/dyntext
439 int yyparse (); // Allow yyparse actions to access
440 Vaddr stack_base; // Stack base
442 // Write experiment header to comment queue
443 void write_header ();
444 void write_coll_params ();
446 Exp_status find_expdir (char *directory_name);
448 // Invoke the parser to process a file.
449 void read_data_file (const char*, const char*);
450 int read_log_file ();
451 void read_labels_file ();
452 void read_notes_file ();
453 void read_archives ();
454 int read_java_classes_file ();
455 void read_map_file ();
456 int read_overview_file ();
457 int read_dyntext_file ();
458 void read_omp_file ();
459 void read_omp_preg ();
460 void read_omp_task ();
461 void read_ifreq_file ();
462 void read_frameinfo_file ();
464 // Functions to process the log and loadobjects file entries
465 // They are deliberately made virtual to overload them
467 virtual int process_arglist_cmd (char *, char *);
468 virtual int process_desc_start_cmd (char *, hrtime_t, char *, char *, int, char *);
469 virtual int process_desc_started_cmd (char *, hrtime_t, char *, char *, int, char *);
470 virtual int process_fn_load_cmd (Module *mod, char *fname, Vaddr vaddr, int fsize, hrtime_t ts);
471 virtual int process_fn_unload_cmd (char *, Vaddr, hrtime_t);
472 virtual int process_hwcounter_cmd (char *, int, char *, char *, int, int, int, char *);
473 virtual int process_hwsimctr_cmd (char *, int, char *, char *, char*, int, int, int, int, int);
474 virtual int process_jcm_load_cmd (char*, Vaddr, Vaddr, int, hrtime_t);
475 virtual int process_jcm_unload_cmd (char*, Vaddr, hrtime_t);
476 virtual int process_Linux_kernel_cmd (hrtime_t);
477 virtual int process_jthr_end_cmd (char *, uint64_t, Vaddr, Vaddr, hrtime_t);
478 virtual int process_jthr_start_cmd (char *, char *, char *, char *, uint64_t, Vaddr, Vaddr, hrtime_t);
479 virtual int process_gc_end_cmd (hrtime_t);
480 virtual int process_gc_start_cmd (hrtime_t);
481 virtual int process_sample_cmd (char *, hrtime_t, int id, char *lbl);
482 virtual int process_sample_sig_cmd (char *, int);
483 virtual int process_seg_map_cmd (char *, hrtime_t, Vaddr, int, int, int64_t, int64_t, int64_t, char *);
484 virtual int process_seg_unmap_cmd (char *, hrtime_t, Vaddr);
486 // creation time for experiment
488 hrtime_t exp_rel_start_time; // start of exp. relative to founder
489 bool exp_rel_start_time_set;
490 Vector<UserLabel*> *userLabels; // List of er_labels
491 int userExpId; // user value for EXPID
492 int expIdx; // DbeSession exp identifier
493 PRBTree *jmaps; // JAVA_CLASSES: (id,time)->Histable
494 Experiment* baseFounder; // outermost experiment (null until lazily computed)
496 // Represents a file in experiment
497 class ExperimentFile;
499 // XML handler to parse various experiment files
500 class ExperimentHandler;
501 class ExperimentLabelsHandler;
503 uint64_t readPacket (Data_window *dwin, Data_window::Span *span);
504 void readPacket (Data_window *dwin, char *ptr, PacketDescriptor *pDscr,
505 DataDescriptor *dDscr, int arg, uint64_t pktsz);
508 DataDescriptor *get_profile_events ();
509 DataDescriptor *get_sync_events ();
510 DataDescriptor *get_hwc_events ();
511 DataDescriptor *get_heap_events ();
512 DataDescriptor *get_heapsz_events ();
513 DataDescriptor *get_iotrace_events ();
514 DataDescriptor *get_race_events ();
515 DataDescriptor *get_deadlock_events ();
516 DataDescriptor *get_sample_events ();
517 DataDescriptor *get_gc_events ();
518 DataDescriptor *getDataDescriptor (int data_id);
519 DataDescriptor *newDataDescriptor (int data_id, int flags = 0,
520 DataDescriptor *master_dDscr = NULL);
522 // Frame info data structures and methods
524 struct RawFramePacket;
526 Vector<RawFramePacket*>*frmpckts; // frame info data
527 static int frUidCmp (const void*, const void*);
528 RawFramePacket *find_frame_packet (uint64_t uid);
530 static const int CHUNKSZ = 16384;
535 Vector<UIDnode*> *uidnodes;
536 bool resolveFrameInfo;
538 int tiny_threshold; /* optimize away tiny experiments which ran
539 * for less than specified time (ms): default 0 */
541 static int uidNodeCmp (const void *a, const void *b);
542 UIDnode *add_uid (Data_window *dwin, uint64_t uid, int size, uint32_t *array, uint64_t link_uid);
543 UIDnode *add_uid (Data_window *dwin, uint64_t uid, int size, uint64_t *array, uint64_t link_uid);
544 UIDnode *new_uid_node (uint64_t uid, uint64_t val);
545 UIDnode *get_uid_node (uint64_t uid, uint64_t val);
546 UIDnode *get_uid_node (uint64_t uid);
547 UIDnode *find_uid_node (uint64_t uid);
549 ExperimentFile *logFile;
552 Vector<DataDescriptor*> *dataDscrs;
553 Vector<PacketDescriptor*> *pcktDscrs;
554 long blksz; // binary data file block size
556 // Processed data packets
557 DataView *openMPdata; // OMP fork events
559 // Map events to OpenMP parallel regions and tasks
560 Map2D<uint32_t, hrtime_t, uint64_t> *mapPRid;
561 Map2D<uint32_t, hrtime_t, void*> *mapPReg;
562 Map2D<uint32_t, hrtime_t, void*> *mapTask;
565 Map<const char*, DbeFile *> *archiveMap;
566 Map<const char*, SourceFile*>*sourcesMap;
570 void post_process ();
571 void constructJavaStack (FramePacket *, UIDnode *, Map<uint64_t, uint64_t> *);
572 void resolve_frame_info (DataDescriptor*);
573 void cleanup_cstk_ctx_chunk ();
574 void register_metric (Metric::Type type);
575 void register_metric (Hwcentry *ctr, const char* aux, const char* username);
577 Sample *sample_last_used;
578 GCEvent *gcevent_last_used;
579 char *first_sample_label;
580 Module *get_jclass (const char *className, const char *fileName);
581 LoadObject *get_j_lo (const char *className, const char *fileName);
583 Vector<BaseMetric*> *metrics;
584 Vector<JThread*> *jthreads; // master list of Java threads
585 Vector<JThread*> *jthreads_idx; // index in the master list
586 Vector<GCEvent*> *gcevents;
587 Vector<UnmapChunk*> *heapUnmapEvents;
588 Vector<Sample*> *samples; // Array of Sample pointers
590 DefaultMap<int64_t, FileData*> *fDataMap; // list of FileData objects using the virtual File descriptor as the key
591 DefaultMap<int, int64_t> *vFdMap; // list of virtual file descrptors using the file descriptor as the key
593 Vector<Vector<Histable*>*> *tagObjs; // tag objects
596 SegMem **smemHTable; // hash table for SegMem's
597 DbeInstr **instHTable; // hash table for DbeInstr
598 Map<unsigned long long, JMethod*> *jmidHTable; // hash table for jmid
600 // identity of target process
606 // Map file processing related data
621 void mrec_insert (MapRecord *mrec);
622 SegMem *update_ts_in_maps (Vaddr addr, hrtime_t ts);
623 int read_warn_file ();
624 LoadObject *get_dynfunc_lo (const char *loName);
625 Function *create_dynfunc (Module *mod, char *fname, int64_t vaddr, int64_t fsize);
626 char *get_archived_name (const char *fname, bool archiveFile = false);
628 Vector<MapRecord*> *mrecs;
631 void add_evt_time_to_profile_events (DataDescriptor *dDscr);
632 DataView *create_heapsz_data_view (DataView *heap_dview);
633 void compute_heapsz_data_view (DataView *heapsz_dview);
642 uint32_t tid; // system thread id
643 Vaddr jthr; // recorded Java thread id
644 Vaddr jenv; // recorded JNIEnv id
645 uint32_t jthr_id; // internal JThread object id
680 class ExperimentLoadCancelException
684 ExperimentLoadCancelException () { };
686 ~ExperimentLoadCancelException () { };
690 #endif /* _EEXPERIMENT_H */