There are two condition that needs to be evaluated and treated.
First, you need to stop taking Ibuprofen, and visit your physician or gastroenterologist as soon as possible to inform about spitting or coughing up some blood.
This bleeding is probably due to your stomach lining (mucosa) being irritated or even damaged because of frequent use of Ibupfofen (significant GI bleeding can be observed as early as three days after starting an ibuprofen regimen in otherwise healthy people).
Another thing is your painful menstrual period or dysmenorrhea (primary or secondary due to endometriosis, pelvic inflammatory disease, and other conditions).
Consult gynecologist!
Best wishes!
Marija