Previous: Profile File Location, Up: Profiling
char* options, char* name, char* version, char* extensionchar* name, char* version, char* extensionPrepare a directory and return a file name (actually a path) suitable for writing profile information. The functions return a pointer to a string; it should be freed when no longer needed. For
profile_path_makethe directory and file name are chosen in the same way as for the `Profile' class when instantiated with mode set toreadexcept that the path name ends with extension rather than.pro. Functionprofile_path_make_optsis similar, except its as though mode were set toread:options.The directory will be created if not present, however nothing will be done with the file itself. That is, no attempt will be made to open the file or to see if it already exists.
In the example below a file name is constructed and used for free-form output.
// File name will contain name of benchmark. char* const pname = profile_path_make("pp_name","pp_ver","txt"); pp_file = fopen(pname,"w"); fprintf(pp_file,"This is my file so I'll write data my way!\n"); // File name will contain full benchmark id. char* const pname2 = profile_path_make_opts("per=benchmark-id","pp_name","pp_ver","txt");
char* mode, char* name, char* versionConstruct a profile object, open a profile file, and start reading or writing it. Argument mode must start with `read', `write', or `read/write'. It may also be followed by options in the form opt
=val:...If mode is `read', file will be read; `write', file will be written; and if `read/write' then file will be read and then written. To determine if file was successfully open use
file_is_open.If `per=benchmark-id' is present then profile file names are constructed using the entire benchmark id. If `per=per-benchmark-name' is present or if there is no `per' option, then profile file names use the first two components of the benchmark id.
Argument name specifies the name of the profiler (which can be anything valid in a file name). The file will be placed in a directory named name which is a subdirectory of the directory pointed to by RTI profile_dir. Argument version specifies a profiler version, this is used to name the profile file. Note that name and version are used only for locating the profile file.
Suppose RTI profile_dir is set to `"/home/jones/profile"' and that benchmark `gentest' is being run, then the name of the profile file will be: `/home/jones/profile/ez-hybrid/gentest-1.0.pro'.
If mode is `write' then a header will be written, if mode is `read' or `read/write' a header will be read and execution will end with a fatal error if the byte order (big or little endian) or data model (size of integers, etc.) don't match.
The file will be closed when the
Profileobject's destructor is called.The examples below show file naming differences obtained with the `per' option. The difference is significant when running a batch with, say, benchmark id's
lsu.gentest.debug.xmrandlsu.gentest.production.abc. The profile1 object would use different files for those, while profile2 would use the same file names.Profile profile1("write:per=benchmark-id","sp-diff","hello"); // Writes file: // .../profile/sp-diff/lsu.gentest.debug.xmr-hello.pro Profile profile2("write","sp-diff","hello"); // Writes file: // .../profile/sp-diff/lsu.gentest-hello.pro
void Profile::init char* mode, char* name, char* versionInitialize profile object. Can only be used if profile constructed with void constructor.
bool Profile::file_is_openReturn `true' if file was successfully open, `false' otherwise. If the file was not successfully open and any data access function is used execution will exit with a fatal error.
char* Profile::profile_file_path_getReturn the path of the profile file. The string will be destroyed with the profile object.
In the example below the profile file is deleted (unlinked) after it is read. Note that a copy of the path is made because the value returned by
profile_file_path_getis not valid when theProfileobject is destroyed, at the end of the enclosing block.RString profile_file_path; { Profile profile("read","basic_block_data_temp","1.0"); profile_file_path = profile.profile_file_path_get(); profile >> insn_segment_data; } unlink(profile_file_path);
void Profile::mode_to_writeSwitch from read mode to write mode. Only valid if profile opened in `read/write' mode.
void Profile::mode_to_read_zerosAll subsequent calls to functions that read from file will behave as though the file contained all zeros. For objects derived from
LObject, this initializes them to an empty state. This might be useful in read-modify-write code for occasions when the data in the file should be discarded rather than read but surrounding the remaining read code with anifstatement would destroy the clarity and beauty of your code.
void Profile::write_obj &objectvoid Profile::write_val objectProfile& Profile::operator << &objectWrite object to file. Argument to
write_objand<<operator is a reference, so usewrite_valfor constants. If object is derived fromLObjectthen itsself_packfunction will be used to correctly write it to the file. If not, its contents will be copied, which can be a problem if it contains pointers.
void Profile::read_obj &objectT Profile::read_valProfile& Profile::operator >> &objectRead object from file. Both
read_objand>>will read directly into the object, which is what you want to do with large data structures. Functionread_valwill return the object, which is okay for small items like integers and doubles. In addition to the functions above, objects derived fromLObjectcan be initialized using data from the file by using aProfileobject as a constructor.
void Profile::read_or_write &objectRead or write object from file, depending on mode of
Profileobject. This function allows one to have a single routine for both writing and reading a profile, eliminating the possibility of inconsistency.Profile profile; profile.init( train_mode ? "write" : "read", "ez-hybrid", "1.0"); profile.read_or_write(case_x_count); profile.read_or_write(case_y_count); profile.read_or_write(sin_info);
void Profile::write_array T* array int num_elementsWrite array of num_elements starting at array of elements of type T.
void Profile::read_array T&* array int& num_elementsvoid Profile::read_array T&* array int num_elementsRead array of elements of type T. If array is `NULL' then storage will be automatically allocated. If num_elements is non-zero or if the second form is used (where the type is not a reference) then execution will end with a fatal error if it differs from the number of elements read from the file. If num_elements is zero it is written with the number of elements read from the file.