10 #include <string_view>
11 #include <unordered_map>
12 #include <unordered_set>
50 template <
typename T1,
typename T2> std::size_t
operator()(
const std::pair<T1, T2>& p)
const
52 auto hash1 = std::hash<T1>{}(p.first);
53 auto hash2 = std::hash<T1>{}(p.second);
55 return (hash1 << 1) + hash1 + hash2;
64 template <
typename T1,
typename T2,
typename T3> std::size_t
operator()(
const std::tuple<T1, T2, T3>& t)
const
77 template <
typename T1,
typename T2,
typename T3,
typename T4> std::size_t
operator()(
const std::pair<std::tuple<T1, T2, T3>,T4>& q)
const
79 return std::get<0>(q.first)
80 ^ std::get<1>(q.first)
81 ^ std::get<2>(q.first)
180 std::string
toString(std::unordered_map<size_t, std::string>& hash_map)
const;
236 bool source_is_core =
true,
bool auto_generate_core_events =
false,
bool auto_wait_resume_os_events =
false);
248 void importFromFile(
const std::string& path,
char delimiter =
',');
298 ErrorCodes taskMigrationEvent(uint64_t time,
const std::string& source_core,
const std::string& destination_core,
const std::string& task,
299 uint64_t task_instance_id);
313 ErrorCodes taskMigrationEvent(uint64_t time,
size_t source_core_hash,
size_t destination_core_hash,
size_t task_hash, uint64_t task_instance_id);
319 bool is_isr =
false);
440 const std::string& signal_value =
"");
474 std::list<std::list<BtfEntry>::iterator>
getEventsForEntity(
const std::string& entity);
496 void insertEvent(std::list<std::list<BtfEntry>::iterator>::iterator pos,
const BtfEntry& entry);
503 std::list<std::list<BtfEntry>::iterator>&
getEntityEvents(
const std::string& entity);
584 void operator=(
BtfFile&) =
delete;
586 void operator=(
BtfFile&&) =
delete;
593 void generateCoreIdleEvent(uint64_t time,
size_t source_hash);
601 void generateCoreExecuteEvent(uint64_t time,
size_t source_hash,
Process::Events process_event);
622 std::string getHeader()
const;
633 uint64_t last_time_{0};
636 std::unordered_map<size_t, Core> cores_;
639 std::unordered_map<std::pair<size_t, uint64_t>, Process, PairHash> tasks_;
642 std::unordered_map<std::pair<size_t, size_t>, Runnable, PairHash> runnables_;
645 std::unordered_map<size_t, Semaphore> semaphores_;
648 std::unordered_map<std::string, std::string> task_core_map_;
651 std::unordered_map<std::pair<size_t, uint64_t>, std::vector<std::pair<size_t, uint64_t>>, PairHash> runnable_stacks_;
654 std::unordered_map<std::pair<std::tuple<size_t, uint64_t, size_t>,
size_t>, bool, QuadrupleHash> os_iswait_;
657 std::unordered_map<size_t, std::string> hash_map_;
660 std::list<BtfEntry> btf_entries_;
663 std::unordered_map<size_t, std::list<std::list<BtfEntry>::iterator>> btf_entries_per_entity_;
666 std::unordered_map<size_t, EntityTypes> type_map_;
669 std::unordered_map<size_t, std::pair<size_t, size_t>> current_running_tasks_;
672 const std::pair<size_t, size_t> no_running_task_{0, 0};
675 std::unordered_map<size_t, bool> did_de_allocated_task_event_occurred_on_core_;
678 std::unordered_map<size_t, uint64_t> stimuli_instance_ids_map_;
681 std::unordered_map<size_t, std::vector<std::list<BtfEntry>::iterator>> runnable_without_task_buffers_;
684 std::unordered_map<size_t, std::vector<std::pair<size_t, uint64_t>>> runnable_without_task_stacks_;
687 std::unordered_map<size_t, uint64_t> runnable_instance_id_counters_;
690 std::vector<std::string> custom_header_entries_;
693 std::unordered_map<size_t, bool> did_task_allocation_event_happen_on_core_;
696 bool auto_suspend_parent_runnable_;
699 bool source_is_core_;
702 bool auto_generate_core_events_;
705 bool auto_wait_resume_os_events_;
708 bool auto_generate_events_{
true};
711 bool ignore_multiple_task_releases_{
false };
Class for a BtfEntry.
Definition: btf.h:92
std::string eventToString() const
Converts union Events into string according to the type_ of the BtfEntry.
Definition: btf.cpp:54
Events event_
Events type of the BtfEntry.
Definition: btf.h:169
size_t target_hash_
Unique hash value of the target.
Definition: btf.h:164
uint64_t source_instance_
Source instance that triggered the event.
Definition: btf.h:162
EntityTypes type_
Entity type of the BtfEntry. The default value is "unknown".
Definition: btf.h:157
uint64_t target_instance_
Target instance of the event.
Definition: btf.h:166
std::string toString(std::unordered_map< size_t, std::string > &hash_map) const
Converts a BtfEntry into string.
Definition: btf.cpp:11
uint64_t time_
Timestamp of the BtfEntry.
Definition: btf.h:154
size_t source_hash_
Unique hash value of the source.
Definition: btf.h:160
std::string note_
Comments added to the BtfEntry.
Definition: btf.h:172
Main class of the btf lib. It contains all necessary functions to import and export a BTF file.
Definition: btf.h:194
BtfFile(std::string path, TimeScales time_scale=TimeScales::nano_seconds, bool auto_suspend_parent_runnable=true, bool source_is_core=true, bool auto_generate_core_events=false, bool auto_wait_resume_os_events=false)
Constructs a BTF file in memory.
Definition: btf.cpp:84
TimeScales
Enum class which contains the possible time scales (pico-, nano-, micro- or milliseconds).
Definition: btf.h:201
ErrorCodes runnableEvent(uint64_t time, const std::string &source, const std::string &runnable, Runnable::Events runnable_event)
Emits a runnable event (source is a core or process depending on the value of the core_is_source para...
Definition: btf.cpp:912
ErrorCodes processEvent(uint64_t time, const std::string &source, const std::string &process, uint64_t process_instance_id, Process::Events process_event, bool is_isr=false)
Emits a task event (except migration). See overloaded function for more information.
Definition: btf.cpp:630
ErrorCodes simulationEventThreadCreation(uint64_t time, const std::string &thread, uint64_t tid, uint64_t pid)
Emits a thread creation event. See overloaded function for more information.
Definition: btf.cpp:2029
ErrorCodes osEvent(uint64_t time, const std::string &process, const std::string &os, OS::Events os_event)
Emits an OS event (source is a core or a process depending on the value of the core_is_source paramet...
Definition: btf.cpp:448
ErrorCodes taskMigrationEvent(uint64_t time, const std::string &source_core, const std::string &destination_core, const std::string &task, uint64_t task_instance_id)
Emits a task migration event. See overloaded function for more information.
Definition: btf.cpp:548
std::list< std::list< BtfEntry >::iterator > getEventsForEntity(const std::string &entity)
Definition: btf.cpp:1792
void headerEntry(const std::string &header_entry)
Writes a custom entry to the header.
Definition: btf.cpp:1759
ErrorCodes simulationEventProcessCreation(uint64_t time, const std::string &process, uint64_t pid, uint64_t ppid)
Emits a process creation event. See overloaded function for more information.
Definition: btf.cpp:1947
ErrorCodes simulationEventProcessName(uint64_t time, const std::string &process, const std::string &name)
Emits a process name event (e.g. name change or initial name). See overloaded function for more infor...
Definition: btf.cpp:1906
std::list< BtfEntry > getAllEvents() const
Gets a list of all events.
Definition: btf.cpp:1896
ErrorCodes coreEvent(uint64_t time, const std::string &core, Core::Events core_event)
Emits a core event. See overloaded function for more information.
Definition: btf.cpp:399
void setIgnoreMultipleTaskReleases(bool value)
Sets the option to ignore multiple releases on a waiting task.
Definition: btf.cpp:2070
ErrorCodes stimulusEvent(uint64_t time, const std::string &source, const std::string &target, Stimulus::Events stimulus_event)
Emits a stimulus event. See overloaded function for more information.
Definition: btf.cpp:1695
ErrorCodes signalEvent(uint64_t time, const std::string &source, const std::string &signal, Signal::Events signal_event, const std::string &signal_value="")
Emits a signal event (source is a core or process depending on the value of the core_is_source parame...
Definition: btf.cpp:1610
void setStringHashMap(std::unordered_map< size_t, std::string > hash_map)
Sets the ID to name translation map. This should only be used for traces that use ID based APIs (e....
Definition: btf.cpp:394
void comment(const std::string &comment)
Emits a comment.
Definition: btf.cpp:1746
void finish()
Writes all BtfEntry instances to file.
Definition: btf.cpp:364
void insertEvent(std::list< std::list< BtfEntry >::iterator >::iterator pos, const BtfEntry &entry)
Inserts an event into the BTF trace. Warning: Use on own risk. No checks are performed and the inse...
Definition: btf.cpp:1780
size_t getNumberOfAllEvents() const
Gets the number of all events.
Definition: btf.cpp:1901
ErrorCodes semaphoreEvent(uint64_t time, const std::string &source, const std::string &target, Semaphore::Events semaphore_event, uint64_t note)
Emits a semaphore event. See overloaded function for more information.
Definition: btf.cpp:1419
void importFromFile(const std::string &path, char delimiter=',')
Appends the data from a BTF file. Currently only import into an empty BTF file is supported.
Definition: btf.cpp:91
ErrorCodes schedulerEvent(uint64_t time, const std::string &source, const std::string &scheduler, Scheduler::Events scheduler_event)
Emits a scheduler event. See overloaded function for more information.
Definition: btf.cpp:1291
ErrorCodes simulationEventThreadName(uint64_t time, const std::string &thread, const std::string &name)
Emits a thread name event (e.g. name change or initial name). See overloaded function for more inform...
Definition: btf.cpp:1989
std::list< std::list< BtfEntry >::iterator > & getEntityEvents(const std::string &entity)
Gets the list of events for a entity.
Definition: btf.cpp:1786
Class for the core (C) events.
Definition: core.h:14
Events
Possible types of core events.
Definition: core.h:36
Events
Possible types of OS events.
Definition: os.h:24
Events
Possible types of Process events.
Definition: process.h:22
Events
Possible types of runnable events.
Definition: runnable.h:43
Events
Possible types of Scheduler events.
Definition: scheduler.h:23
Events
Possible types of Semaphore events.
Definition: semaphore.h:25
Events
Possible types of Signal events.
Definition: btf_signal.h:26
Events
Possible types of simulation events.
Definition: simulation.h:22
Events
Possible types of Stimulus events.
Definition: stimulus.h:23
EntityTypes
All types of entities that are supported by the btf lib.
Definition: btf_entity_types.h:13
ErrorCodes
Error Codes for the btf library.
Definition: common.h:13
This struct generates a hash out of two values (uses a pair).
Definition: btf.h:49
std::size_t operator()(const std::pair< T1, T2 > &p) const
Definition: btf.h:50
This struct generates a hash out of four values (uses a pair where the first parameter is a tuple).
Definition: btf.h:76
std::size_t operator()(const std::pair< std::tuple< T1, T2, T3 >, T4 > &q) const
Definition: btf.h:77
This struct generates a hash out of three values (uses a tuple).
Definition: btf.h:63
std::size_t operator()(const std::tuple< T1, T2, T3 > &t) const
Definition: btf.h:64
Union Class for all supported Events.
Definition: btf.h:102
OS::Events os_event
Definition: btf.h:104
Core::Events core_event
Definition: btf.h:103
Events(Runnable::Events re)
Constructor for a BtfEntry with a Runnable event.
Definition: btf.h:130
Events()
Default Constructor which is assumed to be a BtfEntry with a Core event.
Definition: btf.h:114
Semaphore::Events semaphore_event
Definition: btf.h:108
Stimulus::Events stimulus_event
Definition: btf.h:111
Events(Simulation::Events se)
Constructor for a BtfEntry with a Simulation event.
Definition: btf.h:150
Scheduler::Events scheduler_event
Definition: btf.h:107
Simulation::Events simulation_event
Definition: btf.h:110
Process::Events process_event
Definition: btf.h:105
Events(Signal::Events se)
Constructor for a BtfEntry with a Signal event.
Definition: btf.h:142
Signal::Events signal_event
Definition: btf.h:109
Events(Semaphore::Events sem)
Constructor for a BtfEntry with a Semaphore event.
Definition: btf.h:138
Events(Stimulus::Events ste)
Constructor for a BtfEntry with a Stimulus event.
Definition: btf.h:146
Events(Scheduler::Events sche)
Constructor for a BtfEntry with a Scheduler event.
Definition: btf.h:134
Events(Core::Events ce)
Constructor for a BtfEntry with a Core event.
Definition: btf.h:118
Events(Process::Events te)
Constructor for a BtfEntry with a Process event.
Definition: btf.h:126
Events(OS::Events oe)
Constructor for a BtfEntry with an OS event.
Definition: btf.h:122
Runnable::Events runnable_event
Definition: btf.h:106