aboutsummaryrefslogtreecommitdiffstats
path: root/trace-input.c
Commit message (Collapse)AuthorAge
* trace-cmd: Relicense the library files under LGPLSteven Rostedt2010-02-15
| | | | | | | | | | | | | | | | | | | | All the files that are used to create the libraries: libparsevent and libtracecmd are converted to the LGPL as well as the files to create the plugins. All files now have a boilerplate header that states which license that the file is under. A README file is created as well as the COPYING.LIB which contains the text of the LGPL. All authors of the code that created these files have given their Acks. Acked-by: Darren Hart <dvhltc@us.ibm.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Josh Triplett <josh@joshtriplett.org> Acked-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add locked attribute to record and debug peek freeingSteven Rostedt2010-02-12
| | | | | | | | | | | Add a "locked" attribute to the record structure. This will be set when a peek is returned and cleared on read. This will help debug cases that incorrectly free a record returned by peek. The internal helper function free_next() is added to do the freeing of the next record used by peek. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add tracecmd_get_cursor()Steven Rostedt2010-02-12
| | | | | | | Add the helper routine tracecmd_get_cursor() that returns the offset of the next tracecmd_read_data() or tracecmd_peek_data(). Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add tracecmd_set_all_cpus_to_timestamp()Steven Rostedt2010-02-10
| | | | | | | Add the helper routine tracecmd_set_all_cpus_to_timestamp() to be used to initialize all CPUs to a given time. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add tracecmd_read_prev()Steven Rostedt2010-02-10
| | | | | | | Add the tracecmd_read_prev(handle, record) that returns the record before the given record. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add calc_page_offset() helper routineSteven Rostedt2010-02-10
| | | | | | | | | | Use calc_page_offset() to performe the: offset & (handle->page_size - 1) to prevent any typos and bugs. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add new tracecmd_set_cursor() functionSteven Rostedt2010-02-08
| | | | | | | | | | | | | | | | | | | | | The tracecmd_set_cursor() takes an offset that will cause the next tracecmd_peek_data() or tracecmd_read_data() to return a record at that offset (given that the CPU matches). This is useful when iterating with tracecmd_read_data() and then needing to read a record out of sequence. One can do: while ((record = tracecmd_read_data(h, cpu))) { /* ... */ free_record(record); record = tracecmd_peek_data(h, cpu); save_offset = record->offset; free_record(record); record = tracecmd_read_at(h, o, NULL); /* ... */ tracecmd_set_cursor(h, cpu, save_offset); } Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Compare index of events to proper endSteven Rostedt2010-02-01
| | | | | | | | | The index is the offest from the end of the page, where as the page_size attribute is the offset from the beginning of the data. Fix the compare of the index and the page_size to compare at the same starting point. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Handle junk on last page for tracecmd_read_cpu_last()Steven Rostedt2010-02-01
| | | | | | | | If the last page (or last pages) have just junk on it (timestamps and discarded events), tracecmd_read_cpu_last should not return NULL. It needs to test previous pages. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fix pointer adjustment when skipping paddingSteven Rostedt2010-02-01
| | | | | | | | | When a filter fails to discard an event due to another event writing to the buffer, it makes the first event just padding. But the algorithm to skip the padding added 4 bytes too much to get to the next record. This made the next record corrupted. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Do not return offset of empty CPU bufferSteven Rostedt2010-02-01
| | | | | | | | | | If a one CPU buffer is empty, and a tracecmd_read_at is made to the first page of the next CPU buffer, it mistakenly returns the empty buffer because the offsets still match. Fix this by only returning a CPU buffer if it contains something. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Handle empty CPUs without crashingSteven Rostedt2010-01-15
| | | | | | | | | | | | | The get_page() needs to return -1 on reading a CPU that has no data. Also added checks of get_page() return status that was missing from some callers. Have tracecmd_set_cpu_to_timestamp() also return -1 when reading an empty CPU. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fix cursor on page with timestamp valueSteven Rostedt2010-01-13
| | | | | | | | If the timestamp of the current page matches the parameter, we still need to check if the cached record exists and it too matches the timestamp. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Unload plugins on tracecmd_close()Steven Rostedt2010-01-13
| | | | | | | When the handle is freed, we need to unload the plugins, otherwise we will keep loading them if an app closes and opens a new handle. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add split featureSteven Rostedt2010-01-13
| | | | | | | | | | | | | | | | | | | trace-cmd split [options] -o file [start [end]] -o output file to write to (file.1, file.2, etc) -s n split file up by n seconds -m n split file up by n milliseconds -u n split file up by n microseconds -e n split file up by n events -p n split file up by n pages -r repeat from start to end -c per cpu, that is -p 2 will be 2 pages for each CPU if option is specified, it will split the file up starting at start, and ending at end start - decimal start time in seconds (ex: 75678.923853) if left out, will start at beginning of file end - decimal end time in seconds Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Move merge sort of reading records into librarySteven Rostedt2010-01-13
| | | | | | | | The merge sort of reading the record timestamps and ording the records by time, regardless of CPU, has been moved from the trace-cmd.c file into the libtracecmd library code trace-input.c. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Merge branch 'trace-cmd' into trace-viewSteven Rostedt2010-01-11
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | Updated to handle the API change to tracecmd_open(). modified: kernel-shark.c modified: trace-cmd.h modified: trace-graph-main.c modified: trace-graph.c modified: trace-input.c modified: trace-read.c modified: trace-view-main.c Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| * trace-cmd: Add reference counter to tracecmd_inputSteven Rostedt2010-01-11
| | | | | | | | | | | | | | | | | | | | | | Because different parts of an application may reference a tracecmd_input handle, add a reference counter to make it easier to know when to free the handle. All parts of an application that allocate or calls tracecmd_ref on the handle must now call tracecmd_close on it too. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| * trace-cmd: Rename tracecmd_open to tracecmd_allocSteven Rostedt2010-01-11
|/ | | | | | | | | | | | The tracecmd_open() currently returns a tracecmd_input descriptor that is not finished. The headers still need to be read and data needs to be initialized. Rename tracecmd_open and tracecmd_open_fd to tracecmd_alloc and tracecmd_alloc_fd respectively, and create a new tracecmd_open() and tracecmd_open_fd() that returns a usable descriptor. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Have tracecmd_read_cpu_first() return the first recordSteven Rostedt2010-01-04
| | | | | | | | | | | There was a bug with tracecmd_read_cpu_first() where it may not return the first record for a CPU. If another record was read on the first page the get_page() function would return without reseting the index. The tracecmd_read_cpu_first() needs to always reset the index before returning tracecmd_read_data(). Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Always initialize cpu_data listSteven Rostedt2009-12-31
| | | | | | | | Always intialize the cpu_data list event if the cpu data is empty. The list may still be referenced, and it will segfault if the list is not initialized. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Invalidate peek cached record if timestamp does not matchSteven Rostedt2009-12-30
| | | | | | | | If the recorded timestamp of the cpu cached record does not match the timestamp stored in the cpu_data, that means the record is no longer valid. Free it and read a new record. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Remove uses of tracecmd_refresh_record()Steven Rostedt2009-12-29
| | | | | | | | With the new page ref counts, there's no need for the tracecmd_refresh_record() call. We'll keep it around, but it is now labeled as obsolete. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Allow free_record() to take a NULL argumentSteven Rostedt2009-12-29
| | | | | | | Handle the case that a record failed to allocate, but the code still calls free_record(). Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add page references for recordsSteven Rostedt2009-12-29
| | | | | | | | | | | | | | | | | | | It can be confusing for a user of tracecmd records to keep track when its data is mapped. The data of a record points to a mmapped page of the data file. But currently only one page is mapped at a time. If two records are read that are on different pages, the first record's memory will be unmmaped. Instead of putting the management to the user, this patch changes the design to keep a reference count to the page. When a record is created, it adds one to the page's reference count. The page is only unmmaped when the reference count goes to zero. A check on tracecmd_close is made to make sure all pages have been unmmaped, otherwise a warning is printed. This would happen if a record is not freed properly. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fix memory leak in tracecmd_read_cpu_last()Steven Rostedt2009-12-23
| | | | | | Used valgrind to find a memory leak in tracecmd_read_cpu_last(). Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add final memory clean upsSteven Rostedt2009-12-23
| | | | | | | Made the trace-cmd report free up all memory that it allocated. Thanks to valgrind! Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fix uninitialized and poorly allocated variablesSteven Rostedt2009-12-23
| | | | | | | Used valgrind to discover a lot of memory allocation errors and fixed them up. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Use file long size if no header page is foundSteven Rostedt2009-12-22
| | | | | | | | | | Use the long size of the trace.dat file if no header page is found, instead of using the long size of the host that is running the report. It makes more sense to use the long size that the record was running on than to read the host. This way it at least breaks on all boxes and not just some. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fix trace_peek_data() cached record usageSteven Rostedt2009-12-22
| | | | | | | | | Due to a previous change, the trace_peek_data record cache handling was using the variable "record" and that was never initialized. This patch now sets the record straight. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Have function graph keep record aroundSteven Rostedt2009-12-18
| | | | | | | | | | | | | | | | | | | The function graph tracer looks forward in the trace to determine if a function is a leaf or not. In doing so, it causes the mapping of records to change. This produces a nasty side effect where the caller can have the record stored, and it will suddenly invalidate the record's mapping. This refreshes the record passed in and does a trick by calling the tracecmd_peek_data function that will cache the location after the leaf function's return entry. This unfortunately causes a side effect too where if the last entry in the trace is a leaf function, we can't hide the exit entry and it will print regardless. But this side effect wont crash the application, but the previous side effect will. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Fixed tracecmd_refresh_record()Steven Rostedt2009-12-18
| | | | | | | | Fixed tracecmd_refresh_record to update the CPU iterator properly. Also added the refresh to the tracecmd_peek_data() if it was going to return the cached record. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Add tracecmd_refresh_record()Steven Rostedt2009-12-18
| | | | | | | | | The data field in a struct record is a pointer to an mmap section of memory. If other records are read, this mmap section can be unmapped. The tracecmd_refresh_record() allows users to remap that mmapped section for the record. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd/pevent: Add cpu to struct recordSteven Rostedt2009-12-18
| | | | | | | | | | Most routines that use a record also require a CPU number. It just makes sense to move the CPU to the record. This patch also renames some ambiguous "data" to "record" variables. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Change tracecmd_open() to take file nameSteven Rostedt2009-12-17
| | | | | | | | | | | Rename tracecmd_open() to tracecmd_open_fd and add a new tracecmd_open() to take the name of a file. Also added the API for tracecmd_close() but still need to do proper clean up. It just frees the handle, but does nothing with everything else it allocated. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* trace-cmd: Reset page at ever read by tracecmd_read_at()Steven Rostedt2009-12-15
| | | | | | | | The timestamp was getting messed up by various reads of tracecmd_read_at(). This resets the page everytime that function is used. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Add free_record() to use to free records readSteven Rostedt2009-12-15
| | | | | | | | | This adds a wrapper for freeing the records. It also fixes a comment in tracecmd_peek_data, where the record returned must not be freed. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Comment the tracecmd_input functionsSteven Rostedt2009-12-15
| | | | Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Set to first record in tracecmd_set_cpu_to_timestamp()Steven Rostedt2009-12-15
| | | | | | | | | The algorithm in tracecmd_set_cpu_to_timestamp() depends on the timestamp of the page being for the page. With reading data off the page, the timestamp gets incremented. This resets the timestamp back to the first record on the current page. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Simplify free_page()Steven Rostedt2009-12-15
| | | | | | | | Both read and mmap do the same thing except the mmap version needs to unmap the page on free. The condition should hold the mmap version. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Have get_page() handle size and indexSteven Rostedt2009-12-15
| | | | | | | get_page() already manages the size field of cpu_data, it should also reset index. This does not need to be done in get_next_page(). Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Update timestamp with offsetSteven Rostedt2009-12-15
| | | | | | | | If the offset of the page is modified, reset the timestamp as well. The tracecmd_set_cpu_to_timestamp depends on the timestamp being in sync with the offset. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Remove duplicate setting of offsetSteven Rostedt2009-12-15
| | | | | | | The offset was set at the beginning and again during updating of the page in get_page. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Prevent an infinite loop in searching by timestampSteven Rostedt2009-12-15
| | | | | | | | | | If the search for a record comes down to being on a page where the timestamp is greater than the page but less then the next page to look for, the code will go into an infinite loop. This is because the next page to look for will be the same as the starting page, and it will never continue to move forward. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Add tracecmd_read_cpu_first() and last()Steven Rostedt2009-12-14
| | | | | | Add a interface to get the first and last item per CPU. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* The reading of page info belongs in the mapping of the pageSteven Rostedt2009-12-14
| | | | | | | We need to read the page info when a page is mapped, not when the first element is read. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Move writing to data file to librarySteven Rostedt2009-12-14
| | | | | | | | We need a way to have other applications easily make the output file. This moves the recording of the trace.dat file to the trace-cmd library. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Fix do_read() in case a multiple read is neededSteven Rostedt2009-12-13
| | | | | | | Fix a bug where we tried to read more than needed if a second read is needed. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* Add tracecmd_set_cpu_to_timestamp()Steven Rostedt2009-12-12
| | | | | | | | | This adds an API to set the CPU data field to the location specified by a timestamp. It looks for the page that contains or is before the timestamp to allow for walking forward to find the specified event. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
* squash meSteven Rostedt2009-12-12
| | | | Signed-off-by: Steven Rostedt <rostedt@goodmis.org>