[JAVA-821] reading profiling status disables profiling Created: 30/Apr/13  Updated: 19/Oct/16  Resolved: 01/May/13

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.10.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kay Agahd Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux 64 bit with --keyfile option



 Description   

When reading the profiling status, profiling will be disabled afterwards.
Reproduce:
Turn on profiling: db.setProfilingLevel(1,3000)
PRIMARY> db.setProfilingLevel(1,3000)

{ "was" : 1, "slowms" : 3000, "ok" : 1 }

Execute Java code to read out status:

final CommandResult cr = offerStoreDb.command("profile");

or even:

DBObject command = new BasicDBObject();
command.put("profile", "1");//may be -1 as well
final CommandResult cr = offerStoreDb.command(command);

When re-checking in console, profiling is OFF:
PRIMARY> db.getProfilingLevel()
0



 Comments   
Comment by Kay Agahd [ 02/May/13 ]

Great, I found my mistake: I used a String but it needs to be something numeric! So, instead of

command.put("profile", "-1")

it has to be:

command.put("profile", Integer.valueOf(-1));

or simply with autoboxing:

command.put("profile", -1);

Thanks Jeff!

Comment by Kay Agahd [ 01/May/13 ]

Yes, I'm pretty sure that there was no other process running.
When I was debugging the java code, I checked in a mongo console the profiling status for every code line that was executed. In the same second when the command was sent to the server, the profiling status changed from 1 to 0. I could reproduce this with 1 or -1 in the profile command at any time. I'm out of office today, so I'll try tomorrow again.
Thanks for your help!

Comment by Jeffrey Yemin [ 01/May/13 ]

I put it on a loop:

        System.out.println("Turning on profiling.\nPrevious level was: " + testDB.command(new BasicDBObject("profile", 1)).get("was"));
        for (;;) {
            Thread.sleep(1000);
            System.out.println("Current level is: " + testDB.command(new BasicDBObject("profile", -1)).get("was"));
        }

and it stays at 1:

Turning on profiling.
Previous level was: 0
Current level is: 1
Current level is: 1
Current level is: 1
Current level is: 1
Current level is: 1
Current level is: 1
Current level is: 1
Current level is: 1
...

Are you sure there is no other process running that is turning it off? Have you checked the server logs for a line like:

Wed May  1 10:50:38.062 [conn13] runQuery called test.$cmd { profile: 0 }

Comment by Kay Agahd [ 01/May/13 ]

Jeff, I tried already -1 as well (see my comment in the java code above) but this did not work.
Please turn profiling ON and read the status multiple times (with -1). Some seconds later, profiling will be OFF.

Comment by Jeffrey Yemin [ 01/May/13 ]

Just use -1 as the value. In my tests, this code

        final DB testDB = mongo.getDB("test");
        System.out.println("Starting level: " + testDB.command(new BasicDBObject("profile", -1)).get("was"));
        System.out.println("Turning on profiling.\nPrevious level was: " + testDB.command(new BasicDBObject("profile", 1)).get("was"));
        System.out.println("Current level is: " + testDB.command(new BasicDBObject("profile", -1)).get("was"));
        System.out.println("Turning off profiling.\nPrevious level was: " + testDB.command(new BasicDBObject("profile", 0)).get("was"));
        System.out.println("Current level is: " + testDB.command(new BasicDBObject("profile", -1)).get("was"));
        System.out.println("Current level is: " + testDB.command(new BasicDBObject("profile", -1)).get("was"));

produces this output:

Starting level: 0
Turning on profiling.
Previous level was: 0
Current level is: 1
Turning off profiling.
Previous level was: 1
Current level is: 0
Current level is: 0

Comment by Kay Agahd [ 01/May/13 ]

When this "works as designed", how can we read the profiling status by java without altering the profiling status?

Comment by Jeffrey Yemin [ 01/May/13 ]

Try this:

DBObject command = new BasicDBObject();
command.put("profile", 1);
final CommandResult cr = offerStoreDb.command(command);

The profile command doesn't treat "1" or true (the default value when you use the DB.command() method that just takes the command name) the same as 1.

Generated at Thu Feb 08 08:53:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.