On the eve of 15th August - my contribution to the learning community...
Profiling in C++ is a crucial step in optimizing the performance of your application. It involves analyzing various aspects of the code, such as CPU usage, memory consumption, and execution time, to identify bottlenecks and inefficiencies.
Types of Profiling
CPU Profiling:
Focuses on the amount of time the CPU spends executing different parts of the program.
Identifies functions or code segments that take up most of the CPU time.
Tools: gprof, perf, Visual Studio Profiler.
Memory Profiling:
Monitors the application's memory usage, including allocations, deallocations, and memory leaks.
Helps in identifying memory-intensive operations and optimizing memory management.
Analyzes input/output operations, such as disk access or network communication.
Useful for applications that are I/O bound.
Tools: strace, iotop.
Concurrency Profiling:
Monitors the behavior of multi-threaded programs to identify issues like thread contention, deadlocks, and inefficient parallelism.
Tools: Intel VTune, ThreadSanitizer, gprof.
Today I will discuss about memory profiling - especially memory leak in a C++ program using valgrind.
Please have a look at my video.
It's well-explained here.
Valgrind is a versatile tool for detecting a wide range of memory-related issues in C++ applications. Tools like Memcheck, Helgrind, DRD, and Massif provide comprehensive coverage of memory leaks, invalid accesses, uninitialized memory usage, threading issues, and memory management inefficiencies.
Using Valgrind in the development cycle can significantly improve the stability and performance of your application by identifying and allowing you to fix these memory-related issues.
A CyclicBarrier is a synchronization tool in Java that allows a group of threads to wait for each other to reach a common point before proceeding. Once all threads reach this point (the barrier), they are released simultaneously. The term "cyclic" implies that the barrier can be reused multiple times.
Key Features of CyclicBarrier
Barrier Point: The point where all participating threads must wait before any of them can proceed. Once the last thread reaches this barrier, the barrier is broken, and all threads continue execution.
Cyclic Nature: The barrier is "cyclic" because it can be reused after the waiting threads are released. This allows the same CyclicBarrier instance to be used for multiple cycles of synchronization.
Optional Runnable Action: You can specify a Runnable action that will be executed once the last thread reaches the barrier. This action is executed before the threads are released.
Source Code:
Class StudentTask
package com.somitsolutions.java.cyclicbarrier;
import java.time.LocalTime;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
public class StudentTask implements Runnable {
private String name = "";
private int timeLapseBeforeStarting = 0;
private CyclicBarrier cyclicBarrier = null;
public StudentTask(String name, int timeLapseBeforeStarting, CyclicBarrier cyclicBarrier) {
this.name = name;
this.timeLapseBeforeStarting = timeLapseBeforeStarting;
this.cyclicBarrier = cyclicBarrier;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(timeLapseBeforeStarting);
System.out.println("Thread " + this.name + " has reached the barrier and will wait");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
this.cyclicBarrier.await();
LocalTime localTime = LocalTime.now();
System.out.println(this.name + " is starting at " + localTime .getHour() + " : " + localTime.getMinute() +" : " + localTime.getSecond());
} catch (InterruptedException | BrokenBarrierException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Class classEight:
package com.somitsolutions.java.cyclicbarrier;
import java.util.concurrent.CyclicBarrier;
publicclass ClassEight {
staticfinalintNUMBER_OF_STUDENTS = 3;
staticfinal CyclicBarrier cb = new CyclicBarrier(NUMBER_OF_STUDENTS, ()->{
System.out.println("All threads have reached the barrier. All of them will now proceed...");
});
Thread ridit = new Thread(new StudentTask("Ridit", 1000, cb));
Thread ishan = new Thread(new StudentTask("Ishan", 2000, cb));
Thread manav = new Thread(new StudentTask("Manav", 3000, cb));
publicvoid giveTaskToStudent() {
ridit.start();
ishan.start();
manav.start();
}
}
class Main :
package com.somitsolutions.java.cyclicbarrier;
publicclass Main {
publicstaticvoid main(String[] args) {
// TODO Auto-generated method stub
ClassEight etc = new ClassEight();
etc.giveTaskToStudent();
}
}
The Output:
Thread Ridit has reached the barrier and will wait
Thread Ishan has reached the barrier and will wait
Thread Manav has reached the barrier and will wait
All threads have reached the barrier. All of them will now proceed
I am a software professional having long years of experience. Now i train and coach others in different software technologies. Many of my students are from CBSE 10+2 and they use Turbo C++ at school. When i asked them why their school is still using it, they said probably CBSE board has asked the schools to do so. This is really a dangerous trend - training students with obsolete technologies. Turbo C++ is really prehistoric and it does not have the standard header files of modern C++ as well (like std :: string). I am not sure why CBSE has not banned Turbo C++ in school. While at my training institute, i use Eclipse with CDT plugin alongside Cygwin & GCC compiler and i install the same on my students’ computers, but this should be a normal way of dealing with software rather than an exception.
Not only this, few days back i was having a conversation with one of my friends who is a Professor of CS in a college. He said that most of the colleges in India use Oracle 10g for RDBMS programming. So he suggested that for this either the college authority has to pay an hefty price or use a pirated copy. So why not move to MySQL. But to his shock, he got the answer that when the students will go to other college for external LAB work in the exam, they will most probably get Oracle 10 g and they may not be able to work on it if they are exposed to MySQL in their own college. This is really pathetic.
I have another nightmare to share with you as a technical teacher. Very recently UGC will be coming out with a new Syllabus for college level CS. There they have included Android as one elective subject. Now when i saw the syllabus of that Android course, i was shocked. The colleges have been asked to teach Android using Eclipse with ADT plugin. Now you know, this is passe and most of the Android developers today use Android studio.
No wonder the Indian graduates mostly have half-baked knowledge and remain unemployable for a long time till they learn by rote learning about few historical facts and general knowledge and crack an equally boring Govt. job…
Babus in the Department of Education must be progressive.
It's time for a collective introspection - there is no shortcut to build skills - many night outs in front of a computer is the only answer. To clean up the swamp we must shake up the education system as practised in today's Bharat...
Is anybody listening?
Wake up, please - or else the news like the Rs. 20000 salary per month for a fresh engineering graduate which is even less than that of a driver or a house maid, will dominate the Indian corporate sectors.
A 3D Software Engineer is a programmer who builds software applications specifically designed for 3D graphics and visualization. They essentially bridge the gap between the artistic world of 3D modelling and the technical world of computer science.
Here's a breakdown of their responsibilities:
Software Development:
They write code and develop software applications that deal with 3D graphics, like animation tools, modelling software, or rendering engines.
Understanding 3D Concepts:
They have a deep understanding of 3D graphics and rendering algorithms. This allows them to optimize software for efficient creation and display of 3D visuals.
Problem-Solving:
They troubleshoot and debug software to ensure it functions smoothly and delivers high-quality results.
Collaboration:
They often work alongside software development teams and may even collaborate with 3D artists or designers to understand their needs and create effective tools.
Here are some of the industries that employ 3D Software Engineers:
- Video Game Development
- Film and Animation Studios
- Architecture and Engineering
- Medical Visualization
- Scientific Research
- Building software which will be used for developing flight-simulation, rocket and missile simulation, etc
If you're interested in this field, you'll need strong skills in computer science and mathematics, along with a passion for 3D graphics. Expertise in programming languages like C++ or Python and being familiar with 3D software like Maya or Blender would be a big plus.
My son, Ridit is at the juncture of software development and 3D modelling - having expertise in both of these fields.
Here are some of the animations my son Ridit created using Blender...
This is how it started for Ridit - the journey to learn 3D modelling.
And here are some others...
The passage of Time...
The Water Tornado...
The making of a filter coffee maker... (Fusion 360)
Here's his technical blog...
This blog mainly has stories of his journey as a software professional through the maze called software.
I am not a Nuclear Energy expert - but these days with the help of Gemini and ChatGPT, we can get the right information easily. This blog post is just to disseminate the good work done by the scientists of Bharat.
I am sure the Bharat that my son will be experiencing - will be much different than what we saw after coming out from the engineering colleges in '90s.
#JaiHind
Let's come to the point...
India's ambitious three-stage nuclear program is a strategic plan for developing nuclear power using domestic uranium and thorium reserves. It was formulated by Homi Bhabha, a renowned physicist in the 1950s. The ultimate goal of this program is to achieve long-term energy security for the country by effectively utilizing its abundant thorium reserves.
Here's a breakdown of the three stages:
Stage 1: Pressurized Heavy Water Reactors (PHWRs)
PHWRs use natural uranium as fuel and heavy water (deuterium oxide) as a moderator and coolant.
These reactors are efficient in extracting energy from uranium because heavy water is a more effective neutron moderator than regular water.
India has successfully built and operated numerous PHWRs, and they currently form the backbone of the country's nuclear power generation.
Stage 2: Fast Breeder Reactors (FBRs)
FBRs are designed to produce more fissile material (plutonium) than they consume.
They achieve this by using plutonium or enriched uranium as fuel and a liquid metal (like sodium) as coolant.
The plutonium produced in FBRs can be used as fuel in further reactors, reducing dependence on mined uranium.
India is actively developing FBR technology, and the Prototype Fast Breeder Reactor (PFBR) at Kalpakkam is a significant milestone in this direction.
Stage 3: Advanced Nuclear Power Systems (Thorium Reactors)
This stage focuses on utilizing India's vast thorium reserves for sustainable energy generation.
Thorium itself is not fissile, but it can be converted into fissile uranium-233, which can be used as fuel in nuclear reactors.
Advanced reactor designs like Advanced Heavy Water Reactors (AHWRs) and Molten Salt Reactors (MSRs) are being explored for efficient thorium utilization.
Significance of the 3-stage program:
India has limited uranium reserves but vast thorium reserves. This program allows India to achieve energy security by effectively using its domestic resources.
FBRs help in plutonium production, reducing reliance on imported fissile material.
Thorium-based reactors offer a sustainable and long-term solution for India's energy needs due to the abundance of thorium.
Challenges:
Developing and deploying advanced reactor technologies like FBRs and thorium reactors is a complex and time-consuming process.
Nuclear safety and waste management are critical concerns that need to be addressed effectively.
Overall, India's three-stage nuclear program is a far-sighted approach to ensuring the country's long-term energy security. It leverages domestic resources and promotes sustainable nuclear power generation.
Economic nuke on America - the Baltimore Bridge Collapse ...
Why we must upgrade our critical systems from legacy software which was not written keeping cyber attack in mind.
Watch...
In the early part of my software career, i worked on the Human Machine Interface (HMI) software of two different companies - Omron's NTWin and Mitsubishi's GOT.
As the Human Machine Interface or the HMI software used for SCADA were not written keeping cyber attacks on mind, they are just plain vulnerable to the hackers.
Within the various SCADA solutions, the HMI represents the clearest and most present target for attackers. The HMI acts as a centralised hub for managing critical infrastructure. If an attacker succeeds
in compromising the HMI, nearly anything can be done to the infrastructure itself, including causing physical damage to SCADA equipment. Even if attackers decide not to disrupt operations, they can still exploit the HMI to gather information about a system or disable alarms and notifications meant to alert operators of danger to SCADA equipment.
Read... Humans of Universe... Read...
Here is a document on the vulnerability of the HMI software.
From recent incidents in the USA - the vulnerability of HMI...
Oldsmar, Florida water treatment plant (2021):
Attackers remotely accessed the HMI via insecure remote tools (e.g., TeamViewer with shared/default passwords) and tried to poison water by increasing sodium hydroxide levels.
Unitronics PLC/HMI hacks (2023 onward):
IRGC-affiliated actors ("CyberAv3ngers") defaced HMI screens at U.S. water facilities and elsewhere by exploiting internet-exposed devices with default passwords ("1111"). please educate me on these two incidents
And here we go - the sophisticated malware called Stuxnet - which was responsible for crippling the Iranian nuclear plant...
Can't believe?
Watch how it targeted the SIEMENS PLC at a nuclear plant in Iran.
Stuxnet was crafted to exploit specific vulnerabilities in Windows and the Siemens software stack. The worm utilized multiple zero-day exploits in Windows and targeted Siemens Step7 software running on Windows systems to reprogram PLCs. Since Stuxnet's payload and propagation mechanisms were tailored to this environment, a system running Linux would inherently be immune to these specific exploits.
You know that most legacy HMI software was written using C++, and memory corruption is one of the most common vulnerabilities in HMI software.
I, therefore, was just wondering about the suitability of usage of Rust instead of C++ for writing Human Machine Interface software as the former is designed to handle the memory corruption issue quite nicely.
And voila - my guess was correct...
Rust can be a compelling alternative to C++ for developing SCADA Human-Machine Interfaces (HMIs), especially considering the memory safety advantages Rust offers. Here are some key points on why Rust could be a better choice:
Memory Safety
Elimination of Common Vulnerabilities:
Rust's design inherently prevents common memory-related issues such as buffer overflows, null pointer dereferencing, and use-after-free errors. These types of vulnerabilities are prevalent in systems programmed in C++.
Borrow Checker:
Rust’s borrow checker enforces strict ownership and borrowing rules at compile-time, ensuring that memory safety issues are caught early in the development process, thereby reducing the risk of memory corruption in deployed systems.
Performance
Comparable to C++: Rust is designed to offer performance comparable to C and C++. It achieves this through zero-cost abstractions, meaning you can write high-level code without incurring a performance penalty.
Efficient Concurrency: Rust's concurrency model prevents data races at compile time, allowing for safe and efficient concurrent programming, which is crucial for the high reliability and performance required in SCADA systems.
Modern Language Features
Error Handling: Rust provides robust error handling mechanisms through its Result and Option types, promoting safer and more explicit error management compared to exceptions in C++.
Strong Type System: Rust’s strong and expressive type system helps catch more errors at compile time, reducing runtime bugs and improving overall code quality.
Ecosystem and Tooling
Growing Ecosystem: Rust’s ecosystem is rapidly growing, with many libraries and tools available for systems programming, networking, and interfacing with hardware, which are essential for SCADA systems.
Cargo: Rust’s package manager and build system, Cargo, simplifies dependency management, builds, and project organization, contributing to developer productivity and code maintainability.
Adoption and Community
Industry Adoption: While Rust is still relatively new compared to C++, it has been gaining traction in various industries, including embedded systems and safety-critical applications, demonstrating its suitability for high-reliability domains like SCADA.
Active Community: Rust has a vibrant and supportive community, which helps in quickly resolving issues, sharing best practices, and continuously improving the language and its ecosystem.
Challenges
Learning Curve: The main challenge in adopting Rust is its steep learning curve, especially for developers accustomed to C++. The concepts of ownership, borrowing, and lifetimes can take time to master.
In summary, Rust offers significant advantages in terms of memory safety, performance, and modern language features, making it a strong candidate for developing SCADA HMIs. Its ability to prevent common vulnerabilities associated with memory corruption makes it particularly appealing for the high-security requirements of SCADA systems.
And now as CrowdStrike hitting hard, the C++ memory exception is already in news.
Is null pointer exception the reason for CrowdStrike? see below...