#include <stdio.h>
Software Developer / Architect - Blog
This Blog is first of all memos for me!! From time to time I get exposed to new and cool stuff for developers and architects ,most of the time its a solution for a problem or tips or tricks, so, I would like to track my memos and share it with you, it can save your time and nervous, I hope you will enjoy it - by Yaniv Tzanany.
Search This Blog
Tuesday, April 2, 2024
Cpu cycles counter for linux in C++
#include <stdlib.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <linux/perf_event.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdint.h>
// Structure for perf_event_attr
struct perf_event_attr pe;
// need permsiion on perf_event_open
// to see value ->
// cat /proc/sys/kernel/perf_event_paranoid
//0: Allows access to all users to use perf_event_open for monitoring performance events.
//1: Allows access only to privileged users (typically root) to use perf_event_open.
//2: Disallows access to all users to use perf_event_open
//sudo sysctl kernel.perf_event_paranoid=<new_value>
// Function to initialize and read CPU cycle count
uint64_t read_cpu_cycles() {
// Initialize perf_event_attr structure
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.type = PERF_TYPE_HARDWARE;
pe.config = PERF_COUNT_HW_CPU_CYCLES;
// Open the event
int fd = syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
if (fd == -1) {
perror("Error opening leader %llx");
//exit(EXIT_FAILURE);
return 0;
}
// Read the counter
uint64_t count;
read(fd, &count, sizeof(uint64_t));
// Close the event
close(fd);
return count;
}
Tuesday, January 9, 2024
Tuesday, December 26, 2023
C++ improve your memory allocation
Arena allocation is a C++-only feature that helps you optimize your memory usage and improve performance when working with protocol buffers.
C++ Arena Allocation Guide
Thursday, August 31, 2023
Saturday, June 3, 2023
Tuesday, April 4, 2023
Thursday, March 30, 2023
c++ coding standards (jsf c++)
great pdf with instruction about coding standards
Joint Strike Fighter Air Vehicle C++ Coding Standards
Subscribe to:
Posts (Atom)